简体   繁体   中英

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.

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.

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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