Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Can';不要让selenium点击按钮_Python_Selenium_Xpath_Css Selectors_Webdriverwait - Fatal编程技术网

Python Can';不要让selenium点击按钮

Python Can';不要让selenium点击按钮,python,selenium,xpath,css-selectors,webdriverwait,Python,Selenium,Xpath,Css Selectors,Webdriverwait,我的代码片段 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 W

我的代码片段

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()
当我试着运行它时,我得到了这个,任何帮助都将不胜感激

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="Excel"]"}
按名称(“Excel”)查找元素选择一个名为“Excel”的标记

例如,它会找到如下标记:

<div name='Excel'>Hello</div>.
希望有帮助

有关Python selenium webdriver的更多信息,请使用。这对我帮助很大

所需元素是一个元素,因此要单击该元素,您必须将
元素归纳为可单击()
,您可以使用以下任一选项:

  • 使用
    CSS\u选择器

    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()
    
  • 注意:您必须添加以下导入:

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

您可以共享url吗?由于Excel可能嵌套在某些元素中,因此可能无法直接访问。你可以参考这个链接,我正在自动化一些工作流程,这个URL属于我的工作,所以我不想分享,我相信你理解。还有其他类型的信息可以共享吗?您好,我刚刚尝试了这个方法,在43 apply中得到了这个错误NosTouchElementException Traceback(最近一次调用)。click()44 sleep(3)--->45 excel=driver。通过链接文本(“excel”)查找元素46 excel。click()啊,我明白了,很抱歉我没意识到你在点击一个跨度。单击链接文本可能仅对标记有效。我建议您试用驱动程序。然后通过css选择器('.mat button wrapper span')查找元素!有一次我打印它来查看元素吗?我把它设置为单击,它给了我同样的错误,对不起,如果我问了很多问题,仍然是全新的。嗯。。。看起来span实际上不是一个可点击的元素。你真的需要点击它吗?如果您真的这样做了,我建议您研究如何在JavaScript中执行,因为驱动程序可以使用driver.execute_script()执行JavaScript代码。不过,如果您只是简单地通过css选择器(“button.mat focus indicator”)执行driver.find元素,我认为它也可以正常工作。首先尝试后一种方法。好的,所以我设法找到了一个解决excel=driver的方法。通过xpath(“//按钮[3]”)查找元素。actions=webdriver.common.action\u chains.ActionChains(驱动程序)actions。使用偏移量(excel,20,20)actions将元素移动到元素。单击()actions.perform()谢谢你的意见,我确实设法找到了一个不同的解决方案来解决我的问题,但我确实运行了你的解决方案,它也起了作用!我将不得不阅读有关角度元素的内容,因为我不知道如何管理它们,也确保向您投票
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC