英文:
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:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论