Comparing two websites in two windows using selenium webdriver and python

断了今生、忘了曾经 提交于 2019-12-25 06:06:22

问题


I need to test two websites using selenium webdriver on python. My goal is to make and save changes on one website and then see if the other website changed content accordingly. I want to make a change, then switch to a different window with a different website, then back and forth multiple times. Is it possible? Thank you!


回答1:


You can open a new window by driver.execute_script("window.open('');") and then switch to it by driver.switch_to.window(driver.window_handles[1]) then you can drive it. If you want to switch back to first window driver.switch_to.window(driver.window_handles[0]).

>>> driver.window_handles
[u'{7355ca99-910b-554d-8478-f8a550e0c767}']
>>> driver.execute_script("window.open('');")
>>> driver.window_handles
[u'{7355ca99-910b-554d-8478-f8a550e0c767}', u'{5a0824a9-9d55-0841-87b8-35a26d4a8b83}']
>>> driver.switch_to.window(driver.window_handles[1])
>>> driver.get("http://www.google.com")
>>> driver.switch_to.window(driver.window_handles[0])
>>> driver.get("http://www.yahoo.com")



回答2:


It is possible, just switch between windows using proper commands in selenium webdriver.

If you want to compare graphical elements it's a really good idea to automate it.

For how to navigate between windows look here http://selenium-python.readthedocs.org/en/latest/navigating.html



来源:https://stackoverflow.com/questions/33103115/comparing-two-websites-in-two-windows-using-selenium-webdriver-and-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!