简体   繁体   English

如何获取在新选项卡中单击任何链接时可见的元素列表

[英]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.

相关问题 如何在Java Appium中获取元素的完整列表(包括滚动时可见的元素)? - How to get a complete list of elements (including those which become visible on scrolling) in java appium? 单击选项卡后如何启动新活动? - How do I start a new activity when a tab is clicked? 如何单击iFrame中的链接以打开新标签页并切换到该标签页 - How to click a link within an iFrame which opens a new tab and switch to it 链接(带有重定向)将以隐身方式打开,或在新标签页中打开,或者显式声明新页面。 只是单击不起作用 - Link (with redirects) opens in incognito or when open in new tab, or new page is explicitly declared. Doesn't work when just clicked 在登录页面中,如何处理被Selenium报告为“不可见”的Web元素 - How to handle a web element which is reported as “NOT visible” by Selenium when clicked on, in a login page 即使由于位于另一个选项卡中而不可见,我如何使JavaFX的webview渲染? - How do I make JavaFX's webview render even when not visible due to being in another tab? 如果指定仅包含两个元素的阵列列表的容量,是否会对性能/内存有所帮助? - Is there any performance/memory benefit if the capacity of Array List is being specified which is holding only two elements? 单击链接时如何计数? - How to count when a link is clicked? 单击自定义列表视图中的项目时如何启动新活动 - How to start a new activity when item is clicked of a custom list view 实现ManyToMany关联时,有什么方法可以获取列表中的唯一元素? - Is there any way to get unique elements in list when realizing ManyToMany association?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM