获取所有链接在特定的class-selenium webdriver(java)下/ [英] fetch all links under/in a specific class-selenium webdriver (java)
问题描述
事情是,我正在写一个测试,要求我点击一个随机的 item / product
,但如果通过 By.tagName(a)
创建所有链接的列表,将抓取页面上的所有链接。更准确地说,请本网站,现在我想从 pret
,夏天
销售
,配件
, bt lawn'16
, sale
, lookbook
或点击夏季销售
后,我想随机点击其下的一个产品。任何想法如何做?
这里是我的程序的一个代码片段:
其实你使用的是不正确的 xpath
来定位
, summer
sale
,配件
, bt lawn'16
,销售
, lookbook
,链接尝试如下: -
列表< WebElement> allLinks = driver.findElements(By.cssSelector(a.level0));
随机random = new Random();
WebElement randomLink = allLinks.get(random.nextInt(allLinks.size()));
randomLink.click();
Is there a way to fetch all the links under a specific class?
The thing is, iI am writing a test that requires me to click on a random item/product
but if a create a list of all the links through By.tagName("a")
, It'll fetch ALL the links on the page. To be more exact, consider this website, Now I want to randomly choose from pret
,summer
sale
,accessories
, bt lawn'16
, sale
, lookbook
or after clicking on summer sale
, I want to randomly click on one of the products under it. any idea how to do it?
here is a snippet of my program :
Actually you are using incorrect xpath
to locating pret
,summer
sale
,accessories
, bt lawn'16
, sale
, lookbook
, links try as below :-
List<WebElement> allLinks = driver.findElements(By.cssSelector("a.level0"));
Random random = new Random();
WebElement randomLink = allLinks.get(random.nextInt(allLinks.size()));
randomLink.click();
这篇关于获取所有链接在特定的class-selenium webdriver(java)下/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!