![](/img/trans.png)
[英]How to find matching length of matching elements having same xpath in selenium
[英]How to find the number of elements having the same CSS selector in selenium java?
我正在使用最新版本的 selenium 和 java。
我正在嘗試查找具有相同 css 選擇器的某個網頁中的元素數量,但我不想使用 findElements(By.cssSelector(CSS)).size() 因為“GET”需要很長時間" 元素,然后找到它們的計數。 我不想得到它們,我只需要找到它們的數量,即這個頁面中有多少元素具有相同的 CSS 值。
提前致謝
您需要選擇元素,然后使用這樣的大小,需要找到每個標簽,如 //a、//div 或 //li。 這是一個例子
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.get("https://login.yahoo.com/");
int count = driver.findElements(By.cssSelector("a")).size();
System.out.println(count);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.