问题
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