【问题标题】:Selenium on element click, ElementNotInteractableException元素单击时的硒,ElementNotInteractableException
【发布时间】:2018-02-07 06:49:07
【问题描述】:

我想单击带有 href 的元素以删除 FB 组中的待处理帖子,但 selenium 在第二个 .click() 后崩溃。使用相同的循环,我可以毫无问题地将帖子添加到组中; “删除按钮”列表是有效的,因为当我尝试System.out.println("Delete link: " + delete.get(i).getLocation()); 时,我得到了真实的位置。

while (true){
      if (isloadComplete(driver) && driver.getTitle().contains("My Group")){
         List<WebElement> add = driver.findElements(By.xpath("//a[@data-tooltip-content='approve']"));
         List<WebElement> delete = driver.findElements(By.xpath("//a[@data-tooltip-content='delete']"));
         List<WebElement> articles = driver.findElements(By.xpath("//div[@role='article']"));

         System.out.println("Add links: " + add.size());
         System.out.println("Delete links: " + delete.size());
         System.out.println("Articles: " + articles.size());

         for(int i = 0; i< articles.size(); i++){
             System.out.println("Delete link: " + delete.get(i).getLocation());
             if (articles.get(i).getText().toLowerCase().contains(".com") | articles.get(i).getText().toLowerCase().contains("http")){

                 //System.out.println("Article: " + articles.get(i).getText());

                  delete.get(i).click();
                  WebElement element = (new WebDriverWait(driver, 10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@data-testid='delete_post_confirm_button']")));
                       element.click();

                  }else{
                     add.get(i).click();
                  }

               }
               break;
           }

线程“主”org.openqa.selenium.ElementNotInteractableException 中的异常: 构建信息:版本:'3.4.0',修订:'未知',时间:'未知' 系统信息:主机:'rostyslav-System-Product-Name',ip:'127.0.1.1',os.name:'Linux',os.arch:'amd64',os.version:'4.10.0-32-通用',java.version:'1.8.0_131' 驱动信息:org.openqa.selenium.firefox.FirefoxDriver 功能 [{moz:profile=/tmp/rust_mozprofile.6twl2JYTeRMH, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0.0, moz:accessibilityChecks=假,acceptInsecureCerts=false,browserVersion=55.0.2,platformVersion=4.10.0-32-generic,moz:processID=26485.0,browserName=firefox,javascriptEnabled=true,platformName=linux}] 会话 ID:562a62e4-3aaf-45e3-b7f2-46f741f798a3 在 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 在 sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 在 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 在 java.lang.reflect.Constructor.newInstance(Constructor.java:423) 在 org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:150) 在 org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:115) 在 org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:45) 在 org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164) 在 org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82) 在 org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637) 在 org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:272) 在 org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:82) 在 Main$HelloRunnable.run(Main.java:67) 在 Main.main(Main.java:36)

【问题讨论】:

  • 上面代码中的哪一行导致了这个异常? delete.get(i).click();?
  • @SergeyKorol 是的

标签: java selenium


【解决方案1】:

在实际调用click 之前,您应该等待elementToBeClickable。只需稍微调整以下行,就像您之后所做的一样(通过WebDriverWait):

delete.get(i).click();

【讨论】:

  • 这没有帮助,我得到了超时,在下一个 WebDriverWait 中正在寻找“确认”按钮,但没有人,因为 .click() 没有工作。我只是用 try-catch 跳过它,之后,我删除页面上的所有帖子,刷新页面并且未删除的帖子被删除......我曾经将超时设置为 30 秒,仍然没有帮助)
  • @LittleFox 你能用最新的代码和你在哪里出错的确切行更新你的帖子吗? Stacktrace 也将不胜感激。
猜你喜欢
  • 2018-11-21
  • 2021-03-05
  • 2017-12-26
  • 1970-01-01
  • 2016-08-23
  • 2020-05-20
  • 2018-07-07
  • 1970-01-01
  • 2016-01-12
相关资源
最近更新 更多