Couldn't Click Bottom using xPath Python Selen

2020-02-16 05:04发布

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)

enter image description here

<li class="rtbItem rtbBtn">

xPath:

//*[@id="ctl00_MainContent_ctl00_OverdueItemsGrid_ctl00_ctl02_ctl00_GridToolbar"]/div/div/div/ul/li[3]

Keys.Enter: WebDriverException: Message: unknown error: cannot focus element

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: 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

Keys.Enter: WebDriverException: Message: unknown error: cannot focus element

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

Keys.Enter: WebDriverException: Message: unknown error: cannot focus element

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

Keys.Enter: WebDriverException: Message: unknown error: cannot focus element

Click(): WebDriverException: Message: unknown error: Element ... is not clickable at point (254, 150).

1条回答
家丑人穷心不美
2楼-- · 2020-02-16 05:57

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()
查看更多
登录 后发表回答