Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98779

Selenium xpath issue

$
0
0

I am having a very strange issue using selenium and xpath. I am having a page that renders 25 <a>'s with nested <img/> tags. I need to get using findElements() all this elements. If i get the page source and search trough the text the following substring: "alt="Expand List"" i get 25 appearances. But when i execute the command let items = await driver.findElements(By.xpath("//a[//img[contains(@alt,'Expand List')]]")) I get 32 items. I logged the items in google chrome and to the list are added <a>'s that contain images with different alt values. Any ideas? The piece of code:

    let text = await driver.getPageSource();
    var count = (text.match(/alt="Expand List"/g) || []).length;
    let items = await driver.findElements(By.xpath("//a[//img[contains(@alt,'Expand List')]]"))
    console.log(count, items.length); //outputs 25, 32

enter image description here And this image with the alt Collapse List appears in a <a>

enter image description here


Viewing all articles
Browse latest Browse all 98779

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>