无法使用xPath Python Selenium单击底部 [英] Couldn't Click Bottom using xPath Python Selenium
问题描述
我认为我几乎已经尝试过使用BPath元素中的每个xPath通过使用xPath方法来下载Excel文件,但不知道为什么它们不正确.此外,我还尝试了Click()
和Keys.ENTER
.任何帮助将不胜感激!如果您需要更多详细信息,请告诉我.
I think I pretty much tried every xPath within the Bottom element to download an Excel file by using xPath methods but don't know why they are incorrect. Besides, I also tried Click()
and Keys.ENTER
. Any helps would be very appreciated! Please let me know if you need more details.
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]
键.输入: WebDriverException:消息:未知错误:无法聚焦元素
Keys.Enter: WebDriverException: Message: unknown error: cannot focus element
Click(): WebDriverException:消息:未知错误:元素... 不可点击 (244,149).其他元素将获得点击:...
Click(): WebDriverException: Message: unknown error: Element ... is not clickable at point (244, 149). Other element would receive the click: ...
<a class="rtbWrap" href="#">
xPath:
//*[@id="ctl00_MainContent_ctl00_OverdueItemsGrid_ctl00_ctl02_ctl00_GridToolbar"]/div/div/div/ul/li[3]/a
键.输入: 什么都没发生
Keys.Enter: Nothing Happened
*
* Click():** WebDriverException:消息:未知错误:元素...在点(244,149)处不可单击. 其他元素将获得点击:...
*Click():** WebDriverException: Message: unknown error: Element ... is not clickable at point (244, 149). Other element would receive the click: ...
<span class="rtbIn">
xPath:
//*[@id="ctl00_MainContent_ctl00_OverdueItemsGrid_ctl00_ctl02_ctl00_GridToolbar"]/div/div/div/ul/li[3]/a/span/span/span
键.输入: WebDriverException:消息:未知错误:无法聚焦元素
Keys.Enter: WebDriverException: Message: unknown error: cannot focus element
Click():WebDriverException:消息:未知错误:元素...在点(243,147)处不可单击. 其他元素将获得点击:...
Click(): WebDriverException: Message: unknown error: Element ... is not clickable at point (243, 147). Other element would receive the click: ...
<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
键.输入: WebDriverException:消息:未知错误:无法聚焦元素
Keys.Enter: WebDriverException: Message: unknown error: cannot focus element
Click():WebDriverException:消息:未知错误:元素为 在(203,150)点无法点击
Click(): WebDriverException: Message: unknown error: Element is not clickable at point (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
键.输入: WebDriverException:消息:未知错误:无法聚焦元素
Keys.Enter: WebDriverException: Message: unknown error: cannot focus element
Click(): WebDriverException:消息:未知错误:元素...在点(254,150)处不可单击.
Click(): WebDriverException: Message: unknown error: Element ... is not clickable at point (254, 150).
推荐答案
将click事件替换为操作类,它将解决此异常
Replace click event with action class, which will solve this Exception
from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver)
actions.move_to_element(firstContest).click().perform()
这篇关于无法使用xPath Python Selenium单击底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!