简体   繁体   中英

How to get new appearing links after clicking one in Selenium webdriver?

I'm writing a test when you get all the links from the website and click them. But I need to click some links that in the beginning are hidden or some links that appear only in other pages. Till now, I'm only got to the point that test gets all the active links from homepage and clicks them. I'm new to Selenium webdriver and java, so can you suggest how should I write the test that checks for new appearing links after clicking one or something similar?

I usually write my Selenium tests much more specifically, but were I to attempt this I suspect I would start by making use of findElements(By.tagName("a")) to get all currently available anchors, probably put them into a data object which included if that anchor as been clicked yet and put those data objects into a Set. Map that Set to the currentUrl to keep track of what links were found on what pages. After a click (and recording that you clicked that anchor in its data object) you could check the currentUrl (without any #s) with the last one (without any #s) to determine if that click loaded a new page. If the urls match, I would call findElements again and add those to the existing Set. If they don't match repeat the process for the new currentUrl. Some additional things to be aware of would be handling new Windows and frames, which would require a switchTo and iterating through all the frames (and nested frames).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM