Re-posting my question

I have site with AddCart buttons , and have run code like below . But i have  problem in selecting the addcart buttons as explanined Below .

Please suggest common function which i can use to select the addCart button

For Exmaple :

listelements = driver.findElements(By.xpath(“//*[starts-with(@id,’ProductForm_’)]/div[6]/input”)); –> Here I will get the Three AddKart Buttons with Index of 1,2,3 .

Please suggest . Attaching the ScreenShot

Re-posting my question

But This solution will  work , But refer the below screen shot it fails to identify the  AddCART ButtonRe-posting my question

The Reason it was failed because of the div id change : .//*[@id=’ProductForm_106′]/div[8]/input –> here id of div is 8 Instead of 6 which worked for other two AddCART buttons in the screen shot .

Question is how do we now identify even with dynamic div change ?

Appreciate your help

Add Comment
1 Answer(s)

Can you paste or attach the DOM , one quick solution i could think of is to remove the div at all and try to use //input

Mean while can you try this locator //*[starts-with(@id,’ProductForm_’)]//input , it should select all the input elements inside you product form

kapilag Supporter Answered on December 29, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.