Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Python使用Selenium循环单击?_Python_Selenium_Automation - Fatal编程技术网

如何使用Python使用Selenium循环单击?

如何使用Python使用Selenium循环单击?,python,selenium,automation,Python,Selenium,Automation,我试着用Selenium循环点击, 第一次单击正在工作,但第二次单击出现以下错误: selenium.common.exceptions.elementnotinteractiableexception:Message:Element无法滚动到视图中 代码如下: def send_keys_dropdown(self,url): bot = self.bot bot.get(url) elements = bot.find_element

我试着用Selenium循环点击, 第一次单击正在工作,但第二次单击出现以下错误:
selenium.common.exceptions.elementnotinteractiableexception:Message:Element无法滚动到视图中

代码如下:


    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()


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

似乎在单击操作后执行的元素可能在向下或向上滚动窗口窗体中。 下面的内容可能会帮助您完成它

执行单击操作后,添加以下行

((JavascriptExecutor)驱动程序).executeScript(“参数[0]。scrollIntoView(true);”, 元素)
此处,“elem”是您的单击按钮的web元素。

尝试使用预期条件为“elementToBevible”的WebDriverWait。如果您不能在代码中使用
元素
引用,请查看更多解释。还有一个问题,单击Cancel`链接后,元素的globalize'链接是否会消失?