Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.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访问网站上的密码框。我曾尝试通过xpath查找元素,但没有成功_Python_Selenium_Xpath - Fatal编程技术网

Python 我正在尝试使用selenium访问网站上的密码框。我曾尝试通过xpath查找元素,但没有成功

Python 我正在尝试使用selenium访问网站上的密码框。我曾尝试通过xpath查找元素,但没有成功,python,selenium,xpath,Python,Selenium,Xpath,尝试使用selenium访问网站页面上的密码输入框 我尝试过使用按xpath查找元素,按id查找元素,等等 import csv from selenium import webdriver from selenium.webdriver.support.select import Select import pandas as pd import requests from bs4 import BeautifulSoup option = webdriver.ChromeOptions(

尝试使用selenium访问网站页面上的密码输入框

我尝试过使用
按xpath查找元素,按id查找元素,等等

import csv
from selenium import webdriver
from selenium.webdriver.support.select import Select
import pandas as pd

import requests
from bs4 import BeautifulSoup

option = webdriver.ChromeOptions()
option.add_argument("--incognito")
driver = webdriver.Chrome(executable_path=CHROMEDRIVER_DIR, options = option) 
driver.get("https://xxxxxxxxxxxxxx")
driver.maximize_window()

driver.implicitly_wait(10)
system = driver.find_element_by_xpath("//input[@id='_id:logon:CMS']")
system.send_keys('xxxxxx')
它抛出的错误是

NoTouchElementException:消息:无此类元素:
无法定位元素:
{“方法”:“xpath”,“选择器”:“//input[@id=”\u id:logon:CMS']”}
(会话信息:chrome=76.0.3809.132)


问题是表单在ifame中,您需要首先将驱动程序切换到该iframe。(我还注意到该输入的id不是
\u id:logon:CMS
,而是
\u id:logon:CMS

导入csv
从selenium导入webdriver
从selenium.webdriver.support.select导入选择
作为pd进口熊猫
导入请求
从bs4导入BeautifulSoup
option=webdriver.ChromeOptions()
选项。添加参数(“--incognito”)
driver=webdriver.Chrome(可执行文件路径=CHROMEDRIVER\u目录,选项=option)
驱动程序。获取(“https://analytics.aspire.qa/BOE/BI")
驱动程序。最大化_窗口()
驱动程序。隐式等待(10)
驱动程序。将\u切换到\u帧(“servletBridgeIframe”)
系统=驱动程序。通过xpath(//input[@id=''登录:CMS'])查找元素
系统发送密钥('xxxxxx')

另外,您不需要使用
驱动程序。在此处通过xpath查找元素。这种情况下更方便的方法是使用
驱动程序。通过id查找元素,因此您需要

一旦完成,您应该能够找到您正在寻找的输入

示例代码:

driver.get("https://analytics.aspire.qa/BOE/BI")
wait = WebDriverWait(driver, 10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.NAME, "servletBridgeIframe")))
system = wait.until(EC.element_to_be_clickable((By.ID, "_id0:logon:CMS")))
system.clear()
system.send_keys("foo")

更多信息:

错误消息是:NoSuchElementException:message:没有这样的元素:找不到元素:{“方法”:“xpath”,“选择器”:“//input[@id=”\U id:logon:CMS']”}(会话信息:chrome=76.0.3809.132)。我以前在其他网站上尝试过此代码,但无法使用此特定的代码。