硒无法单击按钮 [英] Can't get selenium to click button

查看:54
本文介绍了硒无法单击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.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.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

  • 这篇关于硒无法单击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆