Python 如何获取元素a[@id=';ks-overlay-close-ks-component9045';],以及div[@id=';ks-component9045';]是弹出窗口
Python 如何获取元素a[@id=';ks-overlay-close-ks-component9045';],以及div[@id=';ks-component9045';]是弹出窗口,python,selenium-firefoxdriver,Python,Selenium Firefoxdriver,但是它失败了,我无法切换到窗口并关闭它这一个看起来不像浏览器弹出窗口。在这种情况下,您不需要切换到窗口和窗口处理函数,只需找到表示关闭按钮的DOM元素并单击它即可 try: all_handles = self.driver.window_handles for handle in all_handles: if handle != now_handle: print handle
但是它失败了,我无法切换到窗口并关闭它这一个看起来不像浏览器弹出窗口。在这种情况下,您不需要切换到窗口和窗口处理函数,只需找到表示关闭按钮的DOM元素并单击它即可
try:
all_handles = self.driver.window_handles
for handle in all_handles:
if handle != now_handle:
print handle
try:
self.driver.switch_to_window(handle)
self.driver.find_element_by_xpath(".//*[@id='ks-overlay-close-ks-component9045']").click()
except:
continue