RE: I have site , where multiple AddCart links are avialable for each product . Is there any way we can write common Method for Addcart Action ?

Ex :

Computer :

Addcart Button for HP : .//*[@id=’ProductForm_31′]/div[6]/input

Addcart Button for MAC : .//*[@id=’ProductForm_15′]/div[6]/input

DVD:

movie1: .//*[@id=’ProductForm_37′]/div[8]/input

movie2 .//*[@id=’ProductForm_90′]/div[6]/input

My question is since each product have add cart Button [ex : flipkart] , how we can select Product X and Relating AddCart Button of X

Please help

Thanks

Add Comment
3 Answers

Hi,

I would suggest to use “starts-with(@id,ProductForm_) in xpath. This will solve following item issue

Addcart Button for HP : .//*[@id=’ProductForm_31′]/div[6]/input

Addcart Button for MAC : .//*[@id=’ProductForm_15′]/div[6]/input

Train Answered on November 26, 2014.

Thanks for the help  Ankit and Ranjodh .

ranjodh are you suggesting me to use the starts with options and store the WebElemets in the list and then get the required index . 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: I have site , where multiple AddCart links are avialable  for each product . Is there any way we can write common Method for Addcart Action ?

But This solution will  work , But refer the below screen shot it fails to identify the  AddCART Button

RE: I have site , where multiple AddCart links are avialable  for each product . Is there any way we can write common Method for Addcart Action ?

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

on November 28, 2014.

Can anybody answer this  question , Appreciate the Help

on November 29, 2014.
Add Comment

Your Answer

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