![](/img/trans.png)
[英]How do I pass options to the Selenium Chrome driver using Python?
[英]How do I click this sign in button using python selenium chrome driver:
我正在嘗試 select 並使用 python selenium chrome 驅動程序單擊登錄按鈕但是我不確定如何定義按鈕:
<button class="Wizard__AccountActionButton-mlu9la-10 fCdYqg flex justify-center items-center font-din">Sign in</button>
要單擊帶有文本作為登錄的元素,您可以使用以下任一定位器策略:
使用css_selector
:
driver.find_element(By.CSS_SELECTOR, "button.flex.justify-center.items-center.font-din").click()
使用xpath
:
driver.find_element(By.XPATH, "//a[contains(@class, 'flex justify-center items-center font-din') and text()='Sign in']").click()
理想情況下,要單擊需要為element_to_be_clickable()
誘導WebDriverWait的元素,您可以使用以下任一Locator Strategies :
使用CSS_SELECTOR
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.flex.justify-center.items-center.font-din"))).click()
使用XPATH
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(@class, 'flex justify-center items-center font-din') and text()='Sign in']"))).click()
注意:您必須添加以下導入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.