我想單擊帶有href的元素來刪除FB組中的待定帖子,但是硒在第二個.click()
後崩潰。使用相同的循環,我可以在沒有任何問題的情況下向帖子添加帖子; 「刪除按鈕」列表是有效的,因爲當我嘗試System.out.println("Delete link: " + delete.get(i).getLocation());
我得到真正的位置。Selenium元素點擊,ElementNotInteractableException
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;
}
異常線程 「main」 org.openqa.selenium.ElementNotInteractableException: 生成信息:版本: '3.4.0',修訂版: '未知',時間: '未知' 系統信息: host:'rostyslav-System-Product-Name',ip:'127.0.1.1',os.name:'Linux',os.arch:'amd64',os.version:'4.10.0-32-generic', java.version:'1.8.0_131' 驅動程序信息:org.openqa.selenium.firefox.FirefoxDriver 功能[{moz:profile =/tmp/rust_mozprofile.6twl2JYTeRMH,rotate = false,timeouts = {implicit = 0.0,pageLoad = 300000.0,script = 30000.0},pageLoadStrategy = normal,platform = ANY,specificationLevel = 0.0,moz:accessibilityChecks = false,acce ptInsecureCerts = 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(本機方法) 在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) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637) at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement。 (Main.java:36)處的Main $ HelloRunnable.run(Main.java:67) 處的org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:82) (java:272)
哪條線在上面的代碼導致該異常? 'delete.get(ⅰ)。單擊();'? –
@SergeyKorol yes –