Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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-running-shirt/pid-10739300/pgid-11072108

Please let me know if there is anything I should paste in here related to the size button.

like image 909
david Avatar asked May 02 '16 16:05

david


1 Answers

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()")
like image 98
Pedro Lobito Avatar answered Oct 07 '22 00:10

Pedro Lobito