如何使用 Selenium 单击 javascript 按钮 [英] How to click a javascript button with Selenium
本文介绍了如何使用 Selenium 单击 javascript 按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 selenium web 驱动程序和 python 单击大小按钮并添加到购物车?
How do I click the size button and add to cart using selenium web driver and python?
这是下面的网站
如果我应该在此处粘贴与大小按钮相关的任何内容,请告诉我.
Please let me know if there is anything I should paste in here related to the size button.
推荐答案
python 示例:
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()")
请注意,('theClassName')[0]
会将第一个元素与 theClassName
匹配,您可能需要增加数量.
Please note that ('theClassName')[0]
will match the first element with theClassName
, you may need to increase the number.
要通过其 ID 获取元素,请使用:
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()")
这篇关于如何使用 Selenium 单击 javascript 按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文