简体   繁体   English

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

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

I've been having trouble creating a function in python using selenium to click a button on a webpage.我一直无法使用 selenium 在 python 中创建 function 以单击网页上的按钮。

I'm following a tutorial that is out of date.我正在关注一个过时的教程。 In the tutorial the code is:在教程中,代码是:

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

Now, I know that selenium has changed how this is done but I am struggling to figure out the correct way of going about it.现在,我知道 selenium 已经改变了这样做的方式,但我正在努力找出正确的方法。

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

this line gives the error:这一行给出了错误:

unexpected EOF while parsing

and

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

this line gives the error:这一行给出了错误:

name "EOL while scanning string literal

This format of code from :这种来自的代码格式:

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

In needs to be written as:中需要写成:

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

or或者

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