我对selenium有点陌生,但我想要构建一个小型的刮板,它将自动登录到Amadeus网站,并放置一些命令和刮响应。
我的问题是我无法在登录页面中找到登录字段。我为登录字段编写了多个X_path,并且chrome能够在测试时识别相同的内容,但是当我在代码中放置相同的X路径时,浏览器就会给出--没有这样的元素:无法定位元素:{“方法”:“xpath”,"selector":"//span@id='w1_dutyCode'//input@type='text'"}。
各位,请帮助我,您可以通过登录链接,如果您能够共享X_path,它将输入登录细节,将不胜感激,
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
# create webdriver object
driver = webdriver.Chrome(executable_path='C:\\Work\\selenium\\chromedriver.exe')
#Opening the Amadeus
driver.get("https://www.sellingplatformconnect.amadeus.com/LoginService/login.jsp?SITE=LOGINURL&LANGUAGE=GB")
driver.maximize_window()
#logging in
sleep(2)
#creating element for user name
[enter image description here][2]
element=driver.find_element_by_xpath("//span[@id='w1_firstInput']//input[@type='text']").send_keys("USER_NAME")
no such element: Unable to locate element: {"method":"xpath","selector":"//span[@id='w1_dutyCode']//input[@type='text']"}发布于 2021-02-23 19:31:14
您有无效的定位器:
//span[@id='w1_firstInput']//input[@type='text']使用具有此值的css选择器的正确定位器:
span#w2_firstInput input然后放一等。sleep(2)是不好的方式,请像下面这样使用WebDriverWait:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# create webdriver object
driver = webdriver.Chrome(executable_path='C:\\Work\\selenium\\chromedriver.exe')
#Opening the Amadeus
driver.get("https://www.sellingplatformconnect.amadeus.com/LoginService/login.jsp?SITE=LOGINURL&LANGUAGE=GB")
driver.maximize_window()
wait = WebDriverWait(driver, 20)
element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'span#w2_firstInput input')))
element.send_keys('username')
#office_id
driver.find_element_by_css_selector('span#w2_officeId input').send_keys('office_id')
#password
driver.find_element_by_css_selector('span#w2_passwordInput input').send_keys('password')
#login
driver.find_element_by_css_selector('div.button.confirm button').click()https://stackoverflow.com/questions/66339392
复制相似问题