【问题标题】:I have a problem with pressing a button by xpath using selenium我在使用 selenium 通过 xpath 按下按钮时遇到问题
【发布时间】:2021-06-30 17:55:14
【问题描述】:

我想按下 XPath 的按钮

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

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

【问题讨论】:

    标签: python selenium web button click


    【解决方案1】:

    这将允许您使用相应的 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
    

    【讨论】:

      【解决方案2】:

      你可以试试这个:

      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
      

      【讨论】:

      • 然后我得到 SyntaxError: invalid syntax
      • 用 ID 代替 xpath 尝试更新的代码。
      猜你喜欢
      • 2021-09-17
      • 2018-04-01
      • 2019-02-07
      • 2021-12-15
      • 1970-01-01
      • 2019-08-23
      • 2022-11-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多