[英]Selenium webdriver: How can I click these links?
<a onclick="requestReportGeneration('857f23e1baa767622a91f970963d8918', 'reportDiv31','CSV')" href="javascript:void[0];">CSV</a>
<a onclick="requestReportGeneration('64107e36323e5877c986edc98a17b6e8', 'reportDiv32','CSV')" href="javascript:void[0];">CSV</a>
<a onclick="requestReportGeneration('2cad4d4e5c8855c47a88b6ddf8345735', 'reportDiv33','CSV')" href="javascript:void[0];">CSV</a>
I have these three links on a page and I want to click each one in turn. 我在页面上有这三个链接,我想依次单击每个链接。 I am reading all the links on the page into a list of WebElements and then I go through each one in turn if the href contains javascript:void[0] I then try to click it:
我将页面上的所有链接读入WebElements列表,然后如果href包含javascript:void [0],则依次浏览每个链接:然后尝试单击它:
for (int i = 0; i < allLinks.size(); i++) {
String reportLink = allLinks.get(i).getAttribute("href");
if (reportLink.contains("javascript:void[0];"))
{
allLinks.get(i).click();
/// Do some more stuff
}
The problem is I keep getting an error saying the element is not visible. 问题是我不断收到错误消息,指出该元素不可见。 I have also tried just loading the page and instead of getting all the links doing
我也尝试过只是加载页面,而不是让所有链接都在做
driver.findElement(By.xpath("//a[contains(@href,\"javascript:void[0]\")]")).click();
but that also just gives element not visible error. 但这也只会给元素带来不可见的错误。 Can anybody tell me why this isn't working?
谁能告诉我为什么这不起作用?
Try putting a breakpoint before the while loop, debug your script, then step into it and use Eclipse's Display tab to interrogate what is up with the links. 尝试在while循环之前放置一个断点,调试脚本,然后进入脚本并使用Eclipse的Display选项卡查询链接的内容。 Try evaluating sample statements like:
尝试评估示例语句,例如:
allLinks.size();
allLinks.get(i).isDisplayed();
allLinks.get(i).isEnabled();
There must be something odd about the links (or the way webdriver is seeing them), but debugging like this will let you find out what it is. 链接(或网络驱动程序查看链接的方式)肯定有些奇怪,但是像这样的调试将使您知道链接的含义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.