硒无法单击按钮

编程入门 行业动态 更新时间:2024-10-27 04:36:27
本文介绍了硒无法单击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

网站检查元素的图片深度图片中的更多内容我的代码段

from selenium import webdriver from selenium.webdrivermon.keys import Keys import time from selenium.webdrivermon.action_chains import ActionChains from selenium.webdrivermon.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from time import sleep import requests /// excel = driver.find_element_by_name('Excel') excel.click()

当我尝试运行它时,我得到了它,任何帮助将不胜感激

I then get this when I try to run it, any help would be appreciated

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="Excel"]"}

推荐答案

所需的元素是 Angular 元素,因此要点击该元素,您必须为 WebDriverWait code> element_to_be_clickable(),您可以使用以下任一定位器策略:

The desired element is a Angular element, so to click on the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • 使用 CSS_SELECTOR :

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[mat-button] > span.mat-button-wrapper span"))).click()

  • 使用 XPATH :

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@mat-button]/span[@class='mat-button-wrapper']//span[text()='Excel']"))).click()

  • 注意:您必须添加以下导入:

  • Note: You have to add the following imports :

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

  • 更多推荐

    硒无法单击按钮

    本文发布于:2023-11-27 20:39:10,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1639519.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:单击   按钮

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!