繁体   English   中英

Amadeus_Login_automation[网页抓取]

[英]Amadeus_Login_automation[Web scraping]

我对 selenium 有点陌生,但想构建一个小型刮板,它会自动登录 Amadeus 网站并输入一些命令并刮掉响应。

我的问题是我无法在登录页面中找到登录字段。 我为登录字段编写了多个 X_path,chrome 在测试时能够识别相同的路径,但是当我在代码中放入相同的 X-path 时,浏览器给出 --- 没有这样的元素:无法定位元素:{"方法":"xpath","selector":"//span[@id='w1_dutyCode']//input[@type='text']"}

这个 Xpath 在 chrome 中匹配但仍然给出错误

伙计们,请帮助我,您可以通过登录链接 go 如果您能分享将输入登录详细信息的 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']"}

您的定位器无效:

//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()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM