[英]selenium + python switch_to_window
I'm writing a scraper that requires selecting a link to open a new window. 我正在编写需要选择链接以打开新窗口的刮板。 To activate the window and check that it is activated, I use :
要激活窗口并检查它是否被激活,我使用:
driver.switch_to_window(driver.window_handles[1])
driver.title
print title
It worked once and then never again. 它曾经工作过一次,然后再也没有。 I did some other check to make certain it was recognizing the windows existence and it does, yet it will not switch:
我做了其他检查,以确保它可以识别Windows的存在,并且可以,但是不会切换:
print len(driver.window_handles)
print driver.window_handles
I'm using the following website: 我正在使用以下网站:
chromedriver = 'C:\Python27\drivers\chromedriver'
driver = webdriver.Chrome(chromedriver)
driver.get("https://ccrecordse.tarrantcountytx.gov/RealEstate/SearchEntry.aspx")
The program enters dates + lease documents, moves to the next page, clicks the document icons to open the new window, but will not switch to the new window. 该程序输入日期+租赁文件,移至下一页,单击文件图标以打开新窗口,但不会切换到新窗口。 I cannot figure out why.
我不知道为什么。
Thanks for your help and let me know if I need to provide more information in my question! 感谢您的帮助,如果需要提供更多信息,请告诉我!
I opened the window by using get_element_by_id.click(). 我使用get_element_by_id.click()打开了窗口。 But it seems I was capturing the change incorrectly, and if I print driver.title, it shows the correct handler.
但是似乎我没有正确捕获更改,并且如果我打印driver.title,它会显示正确的处理程序。 Thank you!
谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.