【问题标题】:how to get the element a[@id='ks-overlay-close-ks-component9045'], and the div[@id='ks-component9045'] is Popup window如何获取元素a[@id='ks-overlay-close-is-component 9045'],而div[@id='ks-component 9045']是Popup window
【发布时间】:2017-05-17 15:52:26
【问题描述】:

Picture: there is Popup window in the html

    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

但它失败了,我无法切换到窗口并关闭它

【问题讨论】:

    标签: python selenium-firefoxdriver


    【解决方案1】:

    这个看起来不像浏览器弹出窗口。在这种情况下,您不需要 switch_to_window 和 window_handles 函数,只需找到代表关闭按钮的 DOM 元素并单击它即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-28
      • 2020-11-24
      • 2020-04-23
      • 2019-03-16
      • 1970-01-01
      • 2014-05-29
      • 2012-08-06
      相关资源
      最近更新 更多