以下是错误:
ElementClickInterceptedException: Message: element click intercepted: Element <a href="report_exec_hc_1.php?report_id=...">SENECA01</a> is not clickable at point (100, 740). Other element would receive the click: <td align="center" class="footer" bgcolor="Black">...</td>
这是代码:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from getpass import getpass
from selenium.webdriver.common.by import By
from selenium.common.exceptions import WebDriverException
import time
opt = Options()
opt.add_argument("--disable-infobars")
opt.add_argument("start-maximized")
opt.add_argument("--disable-extensions")
# Pass the argument 1 to allow and 2 to block
opt.add_experimental_option("prefs", {
"profile.default_content_setting_values.media_stream_mic": 1,
"profile.default_content_setting_values.media_stream_camera": 1,
"profile.default_content_setting_values.geolocation": 1,
"profile.default_content_setting_values.notifications": 1
})
PATH = ("C:\Users\me\AppData\Local\Programs\Python\Python39\chromedriver.exe")
driver = webdriver.Chrome(PATH, chrome_options=opt)
wait = WebDriverWait(driver, 5)
driver.get("https://example.org/logon/login")
print(driver.title)
username = input("Enter in your username: ")
password = getpass("Enter your password: ")
username_textbox = driver.find_element_by_id("username")
username_textbox.send_keys(username)
password_textbox = driver.find_element_by_id("password")
password_textbox.send_keys(password)
login_button = driver.find_element_by_class_name("formstylebut")
login_button.submit()
link = driver.find_element_by_link_text("BI (CAD)")
link.click()
link = driver.find_element_by_link_text("Run a Report")
link.click()
link = wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "SENECA01")))
link = driver.find_element_by_link_text("SENECA01")
link.click()
以下是错误的长期形式:
ElementClickInterceptedException Traceback (most recent call last)
~AppDataLocalTemp/ipykernel_26964/2946665400.py in <module>
48 link = wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "SENECA01")))
49 link = driver.find_element_by_link_text("SENECA01")
---> 50 link.click()
51
52
c:usersmeappdatalocalprogramspythonpython39libsite-packagesseleniumwebdriverremotewebelement.py in click(self)
78 def click(self) -> None:
79 """Clicks the element."""
---> 80 self._execute(Command.CLICK_ELEMENT)
81
82 def submit(self):
c:usersmeappdatalocalprogramspythonpython39libsite-packagesseleniumwebdriverremotewebelement.py in _execute(self, command, params)
691 params = {}
692 params['id'] = self._id
--> 693 return self._parent.execute(command, params)
694
695 def find_element(self, by=By.ID, value=None):
c:usersmeappdatalocalprogramspythonpython39libsite-packagesseleniumwebdriverremotewebdriver.py in execute(self, driver_command, params)
416 response = self.command_executor.execute(driver_command, params)
417 if response:
--> 418 self.error_handler.check_response(response)
419 response['value'] = self._unwrap_value(
420 response.get('value', None))
c:usersmeappdatalocalprogramspythonpython39libsite-packagesseleniumwebdriverremoteerrorhandler.py in check_response(self, response)
241 alert_text = value['alert'].get('text')
242 raise exception_class(message, screen, stacktrace, alert_text) # type: ignore[call-arg] # mypy is not smart enough here
--> 243 raise exception_class(message, screen, stacktrace)
244
245 def _value_or_default(self, obj: Mapping[_KT, _VT], key: _KT, default: _VT) -> _VT:
ElementClickInterceptedException: Message: element click intercepted: Element <a href="report_exec_hc_1.php?report_id=...">SENECA01</a> is not clickable at point (100, 740). Other element would receive the click: <td align="center" class="footer" bgcolor="Black">...</td>
在您的代码中
link = wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "SENECA01")))
link = driver.find_element_by_link_text("SENECA01")
link.click()
您正在使用此链接_文本
SENECA01
此错误
ElementClickInterceptedException: Message: element click intercepted: Element <a href="report_exec_hc_1.php?report_id=...">SENECA01</a> is not clickable at point (100, 740). Other element would receive the click: <td align="center" class="footer" bgcolor="Black">...</td>
意味着,您尝试交互的元素不在selenium视口中,因此其他元素正在接收单击。
为了解决这个问题:
1.使用ActionChains
wait = WebDriverWait(driver, 30)
ActionChains(driver).move_to_element(wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "FIRMI01")))).click().perform()
导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
2.滚动到特定元素
wait = WebDriverWait(driver, 30)
driver.execute_script("arguments[0].scrollIntoView(true);", wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "FIRMI01"))))