Home > Software design >  Writing a line of code with Selenium Webdriver in Python
Writing a line of code with Selenium Webdriver in Python

Time:08-06

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[@]').click()

this line gives the error:

unexpected EOF while parsing

and

driver.find_element("xpath", '//*[@].click()

this line gives the error:

name "EOL while scanning string literal

CodePudding user response:

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[@]').click()
  • Related