英文:
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("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
得分: 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 <li>
so you should locate li
tags.
Change your code to this:
driver.findElements(By.cssSelector(".search-results__list > li")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论