我在使用 selenium 通过 xpath 按下按钮时遇到问题

I have a problem with pressing a button by xpath using selenium

我想按下 XPath 为

的按钮
//*[@id="rass-action-proceed"]

我不知道如何使用硒。有人可以帮我吗?

你可以试试这个:

driver.find_element_by_id("rass-action-proceed").click()

或显式等待:

WebDriverWait(driver , 10).until(EC.element_to_be_clickable((By.ID, "rass-action-proceed"))).click()

确保导入:

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

这将允许您使用相应的 XPath 执行此操作:

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

elem = driver.find_element_by_xpath('//a[@id="rass-action-proceed"]')
elem.click() # Using WebElements 'click()' method for sheer simplicity