【问题标题】:How to loop clicks with Selenium using Python?如何使用 Python 使用 Selenium 循环点击?
【发布时间】:2019-11-11 23:10:26
【问题描述】:

我正在尝试使用 Selenium 循环点击, 第一次点击有效,但第二次出现以下错误: selenium.common.exceptions.ElementNotInteractableException: Message: Element could not be scrolled into view

代码如下:


    def send_keys_dropdown(self,url):
        bot = self.bot
        bot.get(url)
        elements = bot.find_elements_by_xpath("//a[@data-tag='globalize']")
        for elem in elements:
            class_of_element = elem.get_attribute("class")
            if class_of_element == 'CsLinkButton':
                elem.click()
                time.sleep(5)
                # close icon
                bot.find_element_by_xpath("//a[@data-tag='cmdCancel']").click()

如何在循环中单击这些元素?谢谢!

【问题讨论】:

  • 尝试使用预期条件为“ElementToBeVisible”的 WebDriverWait。
  • 如果您不能在代码中使用elements 引用,请查看here 以获得更多解释。还有一个问题,globalize' link disappear for the element once you click on the Cancel` 链接有吗?

标签: python selenium automation


【解决方案1】:

似乎在单击操作后执行的元素可能在向下或向上滚动窗口形式内。 以下内容可能会对您有所帮助。

执行点击操作后添加以下行。

((JavascriptExecutor) 驱动程序).executeScript("arguments[0].scrollIntoView(true);", 元素); 这里,"elem" 是您的 click 按钮的网络元素。

【讨论】:

    猜你喜欢
    • 2019-05-12
    • 2021-10-07
    • 2016-09-26
    • 1970-01-01
    • 1970-01-01
    • 2016-01-08
    • 2020-11-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多