[英]How to get list of elements which is visible when any link is being clicked in the new tab
I have a link called "See all the 40 employees on LinkedIn" so when i click this it is opening a new tab where it is showing all the 40 people list with there details individually one after another, so i want to get the total number of employees, so how do i do this, any help would be appreciated.我有一个名为“查看 LinkedIn 上的所有 40 名员工”的链接,所以当我点击它时,它会打开一个新选项卡,其中显示所有 40 人列表以及详细信息一个接一个,所以我想获得总数的员工,所以我该怎么做,任何帮助将不胜感激。 Below is the code snippet.
下面是代码片段。
driver.findElement(By.partialLinkText("employees on LinkedIn").click();
Thread.sleep(3000);
Image Link:图片链接:
List <WebElement> list = driver.findElements(By.className(("search-results__list")));
list.size();
I have tried here to get the size but it always return 1. Image Link:我在这里尝试获取大小,但它总是返回 1。图片链接:
You are locating ul
thats why it returns only single element.您正在定位
ul
这就是它只返回单个元素的原因。 All required details are under <li>
so you should locate li
tags.所有必需的详细信息都在
<li>
下,因此您应该找到li
标签。
Change your code to this:将您的代码更改为:
driver.findElements(By.cssSelector(".search-results__list > li")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.