使用xPath Python Selenium无法单击底部

时间:2018-06-20 15:26:25

标签: python-3.x selenium-webdriver

我认为我几乎已经尝试过使用BPath元素中的每个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)

enter image description here

<li class="rtbItem rtbBtn">

xPath:

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

键。输入: WebDriverException:消息:未知错误:无法聚焦元素

     

Click(): WebDriverException:消息:未知错误:元素...不可点击   (244,149)。其他元素将获得点击:...

<a class="rtbWrap" href="#">

xPath:

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

键。输入:         什么都没发生

*

  

* 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
  

键。输入: 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
  

键。输入: WebDriverException:消息:未知错误:无法聚焦元素

     

Click():WebDriverException:消息:未知错误:元素为   在(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:消息:未知错误:无法聚焦元素

     

Click(): WebDriverException:消息:未知错误:元素...在点(254,150)处不可单击。

1 个答案:

答案 0 :(得分:3)

用操作类替换单击事件,它将解决此异常

from selenium.webdriver.common.action_chains import ActionChains

actions = ActionChains(driver)
actions.move_to_element(firstContest).click().perform()