我使用了明确的等待,并发出警告:
org.openqa.selenium.WebDriverException:元素在点(36,72)不可单击。其他元素将获得点击:…命令持续时间或超时:393毫秒
org.openqa.selenium.WebDriverException:
如果我使用Thread.sleep(2000)我不会收到任何警告。
Thread.sleep(2000)
@Test(dataProvider = "menuData") public void Main(String btnMenu, String TitleResultPage, String Text) throws InterruptedException { WebDriverWait wait = new WebDriverWait(driver, 10); driver.findElement(By.id("navigationPageButton")).click(); try { wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(btnMenu))); } catch (Exception e) { System.out.println("Oh"); } driver.findElement(By.cssSelector(btnMenu)).click(); Assert.assertEquals(driver.findElement(By.cssSelector(TitleResultPage)).getText(), Text); }
你可以通过以下任一过程解决它们:
尝试使用ActionsClass:
ActionsClass
WebElement element = driver.findElement(By.id("navigationPageButton")); Actions actions = new Actions(driver); actions.moveToElement(element).click().build().perform();
尝试用于JavascriptExecutor将元素带入视口中:
JavascriptExecutor
WebElement myelement = driver.findElement(By.id("navigationPageButton")); JavascriptExecutor jse2 = (JavascriptExecutor)driver; jse2.executeScript("arguments[0].scrollIntoView()", myelement);
在这种情况下,请诱导ExplicitWait,即第4点中提到的WebDriverWait。
ExplicitWait
WebDriverWait
在这种情况下, 将ExplicitWaitExpectedConditions设置为,elementToBeClickable以使元素可单击:
ExplicitWaitExpectedConditions
elementToBeClickable
WebDriverWait wait2 = new WebDriverWait(driver, 10); wait2.until(ExpectedConditions.elementToBeClickable(By.id("navigationPageButton")));
在这种情况下,ExplicitWait使用 ExpectedConditions设置invisibilityOfElementLocated为可使Overlay不可见。
WebDriverWait wait3 = new WebDriverWait(driver, 10); wait3.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("ele_to_inv")));
用于JavascriptExecutor直接在元素上发送点击。
WebElement ele = driver.findElement(By.xpath("element_xpath")); JavascriptExecutor executor = (JavascriptExecutor)driver; executor.executeScript("arguments[0].click();", ele);