1

I am trying to click an item in a product page to add to my cart something but I can't do it because I am getting many errors or nothing happens. This is my code :

i = driver.find_element_by_xpath("//button[@class='exclusive']")
i.click

and this is the webpage code:

<p id="add_to_cart" class="buttons_bottom_block no-print">
  <button type="submit" name="Submit" class="exclusive">
    <span>Add to cart</span>
    </button>
</p>

sorry if I made mistake but I'm new! Thanks for your help.

DebanjanB
  • 118,661
  • 30
  • 168
  • 217

1 Answers1

1

To click the item in the product page to add to cart you can use either of the following Locator Strategies:

  • Using css_selector:

    driver.find_element_by_css_selector("p.buttons_bottom_block.no-print>button.exclusive[name='Submit']>span").click()
    
  • Using xpath:

    driver.find_element_by_xpath("//p[@class='buttons_bottom_block no-print']/button[@class='exclusive']/span[text()='Add to cart']").click()
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217