Java – how do I click on a hidden element in selenium webdriver?

I have a grid showing some records When I click on a record and check the element, it shows that it is hidden, but it is visible in the grid

My HTML is:

<a href="http://192.168.1.6/eprint_prod_3.8/settings/othercost_add.aspx?type=edit&id=805" title="Plastic Spiral Bind"
<div style="float: left; width: 99%; overflow: hidden; height: 15px; overflow: hidden"> Plastic Spiral Bind </div>
</a>

The above code is hidden during inspection, but visible in the grid

Selenium Code:

driver.findElement(By.partialLinkText("Plastic Spiral Bind")).click();

Solution

First, store the element in the object. Let's say element, and then write the following code to click the hidden element:

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();",element);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>