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

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

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:

  1. 你可以尝试以下方式
  2. WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(text(),'Claim Reward')]"))).click()
  3. ***或者***
  4. WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//button[@class="chakra-button css-g0vki9"]')).click()
  5. ***或者使用 CSS 选择器***
  6. WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'button.chakra-button.css-g0vki9'))).click()
  7. ***导入部分***
  8. from selenium.webdriver.common.by import By
  9. from selenium.webdriver.support.ui import WebDriverWait
  10. from selenium.webdriver.support import expected_conditions as EC

I've translated the code parts as requested.

英文:

You should try like below

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

OR

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

OR By CSS SELECTOR

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

IMPORT

  1. from selenium.webdriver.common.by import By
  2. from selenium.webdriver.support.ui import WebDriverWait
  3. 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:

确定