Is there a way to fetch all the links under a specific class?
The thing is, iI am writing a test that requires me to click on a random item/product
but if a create a list of all the links through By.tagName("a")
, It'll fetch ALL the links on the page. To be more exact, consider this website, Now I want to randomly choose from pret
,summer
sale
,accessories
, bt lawn'16
, sale
, lookbook
or after clicking on summer sale
, I want to randomly click on one of the products under it. any idea how to do it?
here is a snippet of my program :
Actually you are using incorrect
xpath
to locatingpret
,summer
sale
,accessories
,bt lawn'16
,sale
,lookbook
, links try as below :-If you want to select all the classes from the site you mentioned, please use below xpath:
Then loop through the
WebElements
to get to the desired menu item. Also, it is observed that the sub-menu items are getting displayed after the mouse is hovered on a particular item. To perform the mouse hover operation we have to useActions
class. Please find the below code for your reference.Hope this helps.