繁体   English   中英

在Python中用Selenium Webdriver编写一行代码

[英]Writing a line of code with Selenium Webdriver in Python

我一直无法使用 selenium 在 python 中创建 function 以单击网页上的按钮。

我正在关注一个过时的教程。 在教程中,代码是:

driver.find_element_by_xpath('//div[@data-value="39455542968391"]')

现在,我知道 selenium 已经改变了这样做的方式,但我正在努力找出正确的方法。

driver.find_element(by=By.XPATH, value=('//button[@class="nice-select open"]').click()

这一行给出了错误:

unexpected EOF while parsing

driver.find_element("xpath", '//*[@class="nice-select open"].click()

这一行给出了错误:

name "EOL while scanning string literal

这种来自的代码格式:

driver.find_element_by_xpath('//div[@data-value="39455542968391"]')

中需要写成:

driver.find_element(By.XPATH, "//button[@class='nice-select open']").click()

或者

driver.find_element(By.XPATH, '//button[@class="nice-select open"]').click()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM