【发布时间】:2018-06-20 15:26:24
【问题描述】:
我想我几乎尝试了底部元素中的每个 xPath 来使用 xPath 方法下载 Excel 文件,但不知道为什么它们不正确。此外,我还尝试了Click() 和Keys.ENTER。任何帮助将不胜感激!如果您需要更多详细信息,请告诉我。
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
from selenium.webdriver.support.ui import Select
import time
driver = webdriver.Chrome(r"C:\My\Path\chromedriver")
driver.get('https://reo-central.com/Default.aspx')
elem = driver.find_element_by_name('ctl00$LoginControl$LoginControl$UserName')
elem.clear()
elem.send_keys('MyAccount')
password = driver.find_element_by_name('ctl00$LoginControl$LoginControl$Password')
password.clear()
password.send_keys('MyPassword')
elem.send_keys(Keys.ENTER)
select=Select(driver.find_element_by_id('ddlResponsibleParty'))
select.select_by_value('344860')
Upcoming_Tasks = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, 'WebPagexPath'))
)
print(Upcoming_Tasks.text)
Upcoming_Tasks.click()
Upcoming_Tasks.send_keys(Keys.ENTER)
<li class="rtbItem rtbBtn">
xPath:
//*[@id="ctl00_MainContent_ctl00_OverdueItemsGrid_ctl00_ctl02_ctl00_GridToolbar"]/div/div/div/ul/li[3]
Keys.Enter: WebDriverException:消息:未知错误:无法聚焦元素
Click(): WebDriverException: Message: unknown error: Element ... is not clickable at point (244, 149)。其他元素会收到点击:...
<a class="rtbWrap" href="#">
xPath:
//*[@id="ctl00_MainContent_ctl00_OverdueItemsGrid_ctl00_ctl02_ctl00_GridToolbar"]/div/div/div/ul/li[3]/a
Keys.Enter: 什么都没发生
*
*Click():** WebDriverException: 消息:未知错误:元素 ... 在点 (244, 149) 处不可点击。 其他元素会收到点击:...
<span class="rtbIn">
xPath:
//*[@id="ctl00_MainContent_ctl00_OverdueItemsGrid_ctl00_ctl02_ctl00_GridToolbar"]/div/div/div/ul/li[3]/a/span/span/span
Keys.Enter: WebDriverException:消息:未知错误:无法聚焦元素
Click(): WebDriverException:消息:未知错误:元素 ... 在点 (243, 147) 处不可点击。 其他元素会收到点击:...
<img alt="" src="../images/icons/document-excel.png" class="rtbIcon">
xPath:
//*[@id="ctl00_MainContent_ctl00_OverdueItemsGrid_ctl00_ctl02_ctl00_GridToolbar"]/div/div/div/ul/li[3]/a/span/span/span/img
Keys.Enter: WebDriverException:消息:未知错误:无法聚焦元素
Click(): WebDriverException: Message: unknown error: Element is 在点 (203, 150) 处不可点击
<span class="rtbText">Export to Excel</span>
xPath:
//*[@id="ctl00_MainContent_ctl00_OverdueItemsGrid_ctl00_ctl02_ctl00_GridToolbar"]/div/div/div/ul/li[3]/a/span/span/span/span
Keys.Enter: WebDriverException:消息:未知错误:无法聚焦元素
Click(): WebDriverException: Message: unknown error: Element ... is not clickable at point (254, 150)。
【问题讨论】:
-
所以您无法为该元素获取正确的 Xpath/Locator?
-
我所做的是右键单击并复制我认为正确的元素。有趣的是,我什至不知道如何知道 xPath 是否正确。所以这些 xPath 是复制元素的结果。
标签: python-3.x selenium-webdriver