参考:(Java Selenium)Element is not visible to clcik

Posted 白色单车

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了参考:(Java Selenium)Element is not visible to clcik相关的知识,希望对你有一定的参考价值。

1.The element is not visible to click.

Use Actions or JavascriptExecutor for making it to click.

By Actions:

WebElement element = driver.findElement(By("element_path"));

Actions actions = new Actions(driver);

actions.moveToElement(element).click().perform();

By javascriptExecutor:

JavascriptExecutor jse = (JavascriptExecutor)driver;

jse.executeScript("scroll(250, 0)"); // if the element is on top.

jse.executeScript("scroll(0, 250)"); // if the element is on bottom.

or

JavascriptExecutor jse = (JavascriptExecutor)driver;

jse.executeScript("arguments[0].scrollIntoView()", Webelement); 

Then click on the element.

2.The page is getting refreshed before it is clicking the element.

For this, make the page to wait for few seconds.

3. The element is clickable but there is a spinner/overlay on top of it

The below code will wait until the overlay disppears

By loadingImage = By.id("loading image ID");

WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);

wait.until(ExpectedConditions.invisibilityOfElementLocated(loadingImage));

Then click on the element.

以上是关于参考:(Java Selenium)Element is not visible to clcik的主要内容,如果未能解决你的问题,请参考以下文章

Java+Selenium根据元素创建指定区域截图——Element快照

java selenium怎么等待元素出现并设置一定时间

Selenium+java自动化测试常用知识点

selenium测试(Java)-- 隐式等待

自动化selenium 基本操作方法总结

如何告诉JAVA Selenium WebDriver从html中找到text-element