Mar*_*ria 63 java selenium webdriver selenium-webdriver
我使用了明确的等待,我有警告:
org.openqa.selenium.WebDriverException:元素在点(36,72)处不可点击.其他元素将收到点击:...命令持续时间或超时:393毫秒
如果我使用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);
}
Run Code Online (Sandbox Code Playgroud)
Deb*_*anB 147
这是一个典型的org.openqa.selenium.WebDriverException,它扩展了java.lang.RuntimeException.
此例外的字段是:
protected static final java.lang.String BASE_SUPPORT_URLpublic static final java.lang.String DRIVER_INFOpublic static final java.lang.String SESSION_ID关于您的个人用例,错误告诉所有:
WebDriverException: Element is not clickable at point (x, y). Other element would receive the click
Run Code Online (Sandbox Code Playgroud)
从你的代码块中可以清楚地看出,你已经定义了waitas,WebDriverWait wait = new WebDriverWait(driver, 10);但是click()在ExplicitWait进入游戏之前你正在调用元素上的方法until(ExpectedConditions.elementToBeClickable).
错误Element is not clickable at point (x, y)可能源于不同因素.您可以通过以下任一过程解决它们:
1.由于存在JavaScript或AJAX调用,元素未被点击
尝试使用ActionsClass:
WebElement element = driver.findElement(By.id("navigationPageButton"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();
Run Code Online (Sandbox Code Playgroud)
2.元素未被点击,因为它不在视口内
尝试使用JavascriptExecutor该元素在视口中:
WebElement myelement = driver.findElement(By.id("navigationPageButton"));
JavascriptExecutor jse2 = (JavascriptExecutor)driver;
jse2.executeScript("arguments[0].scrollIntoView()", myelement);
Run Code Online (Sandbox Code Playgroud)
3.在元素可点击之前,页面将被刷新.
在这种情况下,如第4点所述诱导ExplicitWait即WebDriverWait.
4.元素存在于DOM中但不可点击.
在这种情况下, 请将ExplicitWaitExpectedConditions设置elementToBeClickable为可单击的元素:
WebDriverWait wait2 = new WebDriverWait(driver, 10);
wait2.until(ExpectedConditions.elementToBeClickable(By.id("navigationPageButton")));
Run Code Online (Sandbox Code Playgroud)
5.元素存在但具有临时叠加.
在这种情况下,ExplicitWait使用 ExpectedConditionsset设置invisibilityOfElementLocated为Overlay是不可见的.
WebDriverWait wait3 = new WebDriverWait(driver, 10);
wait3.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("ele_to_inv")));
Run Code Online (Sandbox Code Playgroud)
6.元素存在但具有永久叠加.
用于JavascriptExecutor直接在元素上发送单击.
WebElement ele = driver.findElement(By.xpath("element_xpath"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);
Run Code Online (Sandbox Code Playgroud)
小智 12
如果您需要使用Javascript
我们可以使用参数[0] .click()来模拟点击操作.
var element = element(by.linkText('webdriverjs'));
browser.executeScript("arguments[0].click()",element);
Run Code Online (Sandbox Code Playgroud)
你可以试试
WebElement navigationPageButton = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.id("navigationPageButton")));
navigationPageButton.click();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
113842 次 |
| 最近记录: |