使用Selenium Webdriver和python在两个窗口中比较两个网站 [英] Comparing two websites in two windows using selenium webdriver and python
问题描述
我需要在python上使用Selenium Webdriver测试两个网站.我的目标是在一个网站上进行并保存更改,然后查看另一个网站是否相应地更改了内容.我要进行更改,然后切换到具有其他网站的其他窗口,然后多次来回切换.是否有可能?谢谢!
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!
推荐答案
您可以通过driver.execute_script("window.open('');")
打开一个新窗口,然后通过driver.switch_to.window(driver.window_handles[1])
切换到它,然后就可以驱动它了.如果要切换回第一个窗口driver.switch_to.window(driver.window_handles[0])
.
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")
这篇关于使用Selenium Webdriver和python在两个窗口中比较两个网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!