使用XPath在Python上使用Selenium进行点击。

huangapple go评论75阅读模式
英文:

Using xpath to cllick with selenium on python

问题

我试图使用Selenium Python点击“领取奖励”,但无法成功:

详细信息

以下是我的代码:

WebDriverWait(driver,20).until(EC.visibility_of_element_located(By.XPATH, ('//button[@class="chakra-button css-g0vki9"]'))).click()

有人可以帮助我吗?谢谢。

英文:

I'm trying to click "Claim reward" by selenium python and it doesn't work:

Details

Here is my code:

WebDriverWait(driver,20).until(EC.visibility_of_element_located(By.XPATH, ('//button[@class="chakra-button css-g0vki9"]'))).click()

Can someone help me? thank you

答案1

得分: 1

Sure, here are the translated code parts:

你可以尝试以下方式

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(text(),'Claim Reward')]"))).click()


***或者***

    WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//button[@class="chakra-button css-g0vki9"]')).click()

***或者使用 CSS 选择器***

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'button.chakra-button.css-g0vki9'))).click()


***导入部分***

    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC

I've translated the code parts as requested.

英文:

You should try like below

WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(text(),'Claim Reward')]"))).click()

OR

WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//button[@class="chakra-button css-g0vki9"]'))).click()

OR By CSS SELECTOR

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'button.chakra-button.css-g0vki9'))).click()

IMPORT

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

huangapple
  • 本文由 发表于 2023年3月15日 21:34:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75745454.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定