簡體   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