[英]click on list items using java script executor in selenium web driver
I have a requirement to collect multiple links and click on each link to extract some information from the website to the excel.So i have collected all links in one list and i am trying to click on each element depending on the index. 我需要收集多个链接,然后单击每个链接以从网站提取一些信息到excel.So,因此我已将所有链接收集在一个列表中,并且我试图根据索引单击每个元素。 I am not getting any exception and the click is also not performing on the element.I struck in clicking on link using javascript executor.Normal click and actions are not working here.
我没有任何异常,并且元素上的点击也没有执行。我使用javascript executor来点击链接。正常点击和操作在这里不起作用。
List<WebElement> titles=driver.findElements(By.xpath("//*[@class='product-name']"));
for(int i=0;i<titles.size();i++)
{
String title1=titles.get(i).getText();
System.out.println(title1);
Thread.sleep(5000);
if(titles.get(i).isEnabled())
{
System.out.println("TAKE ACTION");
js.executeScript("arguments[0].click();", titles.get(i));
}
}
According to your HTML you could collect all the href
url instead of clicking in the header. 根据您的HTML,您可以收集所有
href
网址,而不用单击标题。
Sample code: 样例代码:
List<WebElement> elements = driver.findElements(By.xpath(".//h2[@class='product-name']//a"));
for (WebElement element : elements) {
driver.navigate().to(element.getAttribute("href"));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.