【发布时间】: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 是的