【问题标题】:submit button in selenium without id and value在没有 id 和值的情况下在 selenium 中提交按钮
【发布时间】:2021-10-22 08:08:41
【问题描述】:

我有一个按钮

<button type="submit" class="btn btn-default waves-effect waves-light"><i class="fa fa-search" aria-hidden="true"></i></button>

我已经测试了所有这些但没有成功

# browser.find_element_by_class_name('fa fa-search').click()
# browser.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[4]/div/form/div/button').click()
# WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="RechAvFormRadio"]/div/button'))).click()

【问题讨论】:

    标签: python-3.x selenium


    【解决方案1】:

    尝试使用这样的 css 选择器:

    button.btn.btn-default.waves-effect.waves-light
    

    或xpath

    //button[contains(@class,'btn btn-default waves-effect waves-light')]
    

    //i[contains(@class,'fa fa-search')]/parent::button
    

    PS:如果我们在HTML DOM 中有唯一条目,请检查dev tools(谷歌浏览器)。

    检查步骤:

    Press F12 in Chrome -> 转到element 部分 -> 做一个CTRL + F -> 然后粘贴xpath 看看,如果你想要的element 用@ 得到高亮 987654331@匹配节点。

    代码试用 1:

    time.sleep(5)
    driver.find_element_by_xpath("//i[contains(@class,'fa fa-search')]/parent::button").click()
    

    代码试用 2:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//i[contains(@class,'fa fa-search')]/parent::button"))).click()
    

    进口:

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

    【讨论】:

    • 回溯:selenium.common.exceptions.ElementClickInterceptedException:消息:元素点击被拦截:元素 在点 (674, 578) 处不可点击。其他元素会收到点击:
      ...
      (会话信息:chrome=94.0.4606.81)
    • 是否有任何重叠的网络元素?
    • 看起来是的
    • 如果可以的话,你能分享一下网页网址吗?
    猜你喜欢
    • 1970-01-01
    • 2011-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-13
    • 2021-12-20
    • 2016-08-29
    • 2012-04-18
    相关资源
    最近更新 更多