获取在新标签页中单击任何链接时可见的元素列表。

huangapple go评论89阅读模式
英文:

How to get list of elements which is visible when any link is being clicked in the new tab

问题

我有一个名为“查看LinkedIn上的所有40名员工”的链接,当我点击它时,会打开一个新的标签页,显示所有40个人的列表,以及他们的详细信息,一个接一个地。所以我想获取员工的总人数,该如何做呢?任何帮助将不胜感激。以下是代码片段。

driver.findElement(By.partialLinkText("employees on LinkedIn")).click();
Thread.sleep(3000);

Image Link:

[![enter image description here][1]][1]

List<WebElement> list = driver.findElements(By.className("search-results__list"));
list.size();

我已经尝试在这里获取大小,但它始终返回1。图像链接:

获取在新标签页中单击任何链接时可见的元素列表。

英文:

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. Below is the code snippet.

driver.findElement(By.partialLinkText(&quot;employees on LinkedIn&quot;).click();
Thread.sleep(3000);

Image Link:

获取在新标签页中单击任何链接时可见的元素列表。

List &lt;WebElement&gt; list = driver.findElements(By.className((&quot;search-results__list&quot;)));
list.size();

I have tried here to get the size but it always return 1. Image Link:

获取在新标签页中单击任何链接时可见的元素列表。

答案1

得分: 0

你定位的是ul,所以只返回单个元素。所有所需的详细信息都在<li>下,所以你应该定位li标签。

将你的代码更改为:

driver.findElements(By.cssSelector(".search-results__list > li"))
英文:

You are locating ul thats why it returns only single element. All required details are under &lt;li&gt; so you should locate li tags.

Change your code to this:

driver.findElements(By.cssSelector(&quot;.search-results__list &gt; li&quot;)

huangapple
  • 本文由 发表于 2020年7月22日 20:53:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/63034687.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定