Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.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 Selenium:Selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素:_Python_Selenium Webdriver - Fatal编程技术网

Python Selenium:Selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素:

Python Selenium:Selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素:,python,selenium-webdriver,Python,Selenium Webdriver,我的代码: driver.find_element_by_xpath("//div[@class='x-grid3-cell-inner x-grid3-col-1']//a").click() # Click on Device eid time.sleep(15) driver.find_element_by_xpath("//table[@id='ping']//button[contains(text(),'Ping')]").click() # click on Ping 获取错误

我的代码:

driver.find_element_by_xpath("//div[@class='x-grid3-cell-inner x-grid3-col-1']//a").click() # Click on Device eid

time.sleep(15)
driver.find_element_by_xpath("//table[@id='ping']//button[contains(text(),'Ping')]").click() # click on Ping
获取错误:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: 
在Chrome和firefox上xpath是正确的,仍然会出现错误吗?有人能帮忙吗?我知道这很愚蠢


一个。

检查元素是否在
iFrame
标记下,如果是,则首先需要切换到框架,然后执行预期操作

iframe = driver.find_element_by_name('frame_name')

driver.switch_to.frame(iframe)
如果它与时间有关,那么在代码中引入隐式和显式等待

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@class='x-grid3-cell-inner x-grid3-col-1']//a"))
element.click()

希望这将有助于检查元素是否在
iFrame
标记下,如果是,则首先需要切换到frame,然后执行预期操作

iframe = driver.find_element_by_name('frame_name')

driver.switch_to.frame(iframe)
如果它与时间有关,那么在代码中引入隐式和显式等待

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@class='x-grid3-cell-inner x-grid3-col-1']//a"))
element.click()

希望这将有所帮助

首先,您必须将url添加到此页面,以便我们可以看到完整的HTML。可能元素在
中,您必须使用
驱动程序。切换到.frame(…)
这是我公司的内部应用程序。还有其他方法吗?首先检查项目是否为
。如果没有框架,则检查xpath是否有较短的内容,即。
“//table[@id='ping']”
非常感谢Furas,问题已解决,有一个框架。我实现了框架概念。:)首先,您必须将url添加到此页面,以便我们可以看到完整的HTML。可能元素在
中,您必须使用
驱动程序。切换到.frame(…)
这是我公司的内部应用程序。还有其他方法吗?首先检查项目是否为
。如果没有框架,则检查xpath是否有较短的内容,即。
“//table[@id='ping']”
非常感谢Furas,问题已解决,有一个框架。我实现了框架概念。:)谢谢纳伦德拉,这是一个iFrame问题。谢谢纳伦德拉,这是一个iFrame问题。