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.

2
  • i.click(). Correct this maybe your syntax is wrong Commented Mar 3, 2019 at 9:50
  • I am getting many errors which are? post add them to the question. Commented Mar 3, 2019 at 11:30

1 Answer 1

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()
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.