Skip to content Skip to sidebar Skip to footer

How To Click A Javascript Button With Selenium

How do I click the size button and add to cart using selenium web driver and python? This is for the website below http://store.nike.com/us/en_us/pd/dri-fit-cool-tailwind-stripe-ru

Solution 1:

A python example:

driver = webdriver.Firefox()
driver.get("http://store.nike.com/us/en_us/pd/dri-fit-cool-tailwind-stripe-running-shirt/pid-10739300/pgid-11072108")
driver.execute_script("document.getElementsByClassName('theClassName')[0].click()")

Please note that ('theClassName')[0] will match the first element with theClassName, you may need to increase the number.


To get the element by its ID, use:

driver = webdriver.Firefox()
driver.get("http://store.nike.com/us/en_us/pd/dri-fit-cool-tailwind-stripe-running-shirt/pid-10739300/pgid-11072108")
driver.execute_script("document.getElementById('theIdName').click()")

Post a Comment for "How To Click A Javascript Button With Selenium"