enter image description here我的代码基本上是登录网站(https://user.sensogram.com/signin)并通过点击按钮下载CSV文件(下载CSV)。但是我收到的错误是:
File "c:\Users\USERPC\Desktop\python\sesno_login.py", line 57, in <module>
csv_file_button.click()
File "C:\Users\USERPC\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\selenium\webdriver\remote\webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Users\USERPC\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\selenium\webdriver\remote\webelement.py", line 628, in _execute
return self._parent.execute(command, params)
File "C:\Users\USERPC\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "C:\Users\USERPC\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\selenium\webdriver\remote\errorhandler.py", line 242, in
check_response raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error:
Element <tspan>...</tspan> is not clickable at point (1232, 413). Other
element would receive the click: <div class="page-loading ng-scope" ng-
if="showPreloader" style="">...</div>
因为某些原因,代码无法在页面上找到点击按钮。这是我到目前为止写的:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.common.exceptions import NoSuchElementException
import time
chromedriver = "/webdrivers/chromedriver"
driver = webdriver.Chrome(chromedriver)
driver.maximize_window()
driver.get('https://user.sensogram.com/signin') #driver.get(url)-- We get
url by using driver which we initialy load.
print ("Opened sensogram")
time.sleep(5) #Just wait for sometime.
email = driver.find_element_by_xpath("//input[@name='usernameSignIn']")
#Find email textaera.
email.send_keys('****') #Send email to this text area.
password = driver.find_element_by_xpath("//input[@name='passwordSignIn']")
#Find password textarea.
password.send_keys('*******') #send password to the password field.
button = driver.find_element_by_xpath("//button[@ng-
click='submitted=true']") #Find login button.
button.click() #Click on login button.
driver.implicitly_wait(10)
csv_file_button = driver.find_element_by_xpath("//*[name()='tspan' and
.='Download CSV']")
csv_file_button.click()
print(csv_file_button)
有人能弄清楚为什么我会继续遇到这种类型的错误吗?加上这是csv文件的网页HTML:
<g class="highcharts-button highcharts-contextbutton highcharts-button-
normal" style="cursor:pointer;vertical-align:center;font-size:12;font-
weight:500;" stroke-linecap="round" transform="translate(379,8)">
<title>Chart context menu</title><rect fill="rgba(0, 0, 0, 0.7)" class="
highcharts- button-box" x="0.5" y="0.5" width="100" height="32" rx="2"
ry="2" stroke="none" stroke-width="1"></rect><text x="7" style="font-
weight:normal;color:#fff;fill:#fff;" y="19"><tspan>Download CSV</tspan>
</text></g>
答案 0 :(得分:0)
有时selenium webdriver找不到元素,所以最好使用javascript executor点击所需的按钮
示例:
js = (JavascriptExecutor) driver;
js.executeScript("$('#downloadcsv').click()");