0

AS per the screen shot there are more then two botton of the add to cart and all button class name are same . so how can i identify the each and every one by the on click event->ajax id enter image description here

7
  • Can you add the HTML code as well so we can help you to select the add to cart button based on the your item
    – NarendraR
    Feb 15 '18 at 10:51
  • how to add the HTML code? i have try this WebElement addtocart=s1.getDriver().findElement(By.className("product-box-add-to-cart-button")); addtocart.click();
    – Rutvi Soni
    Feb 15 '18 at 10:53
  • If your requirement to get all those 2 button then use index in your xpath
    – NarendraR
    Feb 15 '18 at 10:53
  • ok i have to check for that
    – Rutvi Soni
    Feb 15 '18 at 10:55
  • Actually there are compound classes in your tag so className wont work. use this //input[@class='button-2 product-box-add-to-cart-button'] and let me know
    – NarendraR
    Feb 15 '18 at 10:56
1

Without the full DOM structure, I would guess by the UI:

Probably there is a root where the two button elements derive uniquely.

Some common node
└── ├── Image Node
                  ├── Image tag
                  └── Button tag
    ├── QR Code Node
                  ├── QR Code tag
                  └── Button tag

So, if you want to reach the image input, your css selector is .css_class_of_the_image_node input. If you want to reach the image input, your css selector is .css_class_of_the_QR_code_node input.

3
  • To be fully complete, the css selectors would be .css_class_of_the_image_node input .product-box-add-to-cart-button or .css_class_of_the_QR_code_node input .product-box-add-to-cart-button
    – Pieter A
    May 17 '18 at 6:27
  • I think input.product-box-add-to-cart-button is the case, since the product-box-add-to-cart-button is a class of the input elements. Using as you suggested would search for a element which has the named class INSIDE the input element - thus would find nothing because there is nothing inside input elements. May 20 '18 at 12:37
  • 1
    Sorry, I totally missed the 'input' part, also when copy pasting. Your original solution was correct and also agree with your last comment.
    – Pieter A
    May 20 '18 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.