Reputation: 13
I want to click on an <a>
tag, which looked like an element I could click on with a selenium built-in function click()
. I was wondering if somebody perhaps can explain how to determine if such an element is actually clickable for future selenium coding. Thanks
HTML:
<a class="open" data-path="/public/employees/767772/description.json" href="javascript:;" style="display: inline;">
<span class="icon-caret-right"></span><font style="vertical-align: inherit;"><font style="vertical-align: inherit;"> Läs mer
</font></font></a>
When I tried all I got was an error:
DevTools listening on ws://127.0.0.1:56906/devtools/browser/a65af20c-af35-4f09-8390-abce557b8b87
Traceback (most recent call last):
File "c:/Users/hugom/OneDrive/Documents/python web scraping tut/csv tutorials/freelancer.py", line 79, in <module>
a_tag.click()
File "C:\Users\hugom\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Users\hugom\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Users\hugom\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\hugom\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <a class="open" data-path="/public/employees/118883/description.json" href="javascript:;">...</a> is not clickable at point (458, 1242). Other element would receive the click: <img alt="テレビCM放映中!" src="https://cw-assets.crowdworks.jp/assets/banners/fixedfooter-20200104-2000x200-5e5bc753cfe393c01c5797c1647b4fd732631e477d4308cc653f4d994f541200.png" width="1000" height="100">
(Session info: chrome=85.0.4183.102)
Upvotes: 1
Views: 1449
Reputation: 193078
This error message...
ElementClickInterceptedException: Message: element click intercepted: Element <a class="open" data-path="/public/employees/118883/description.json" href="javascript:;">...</a> is not clickable at point (458, 1242). Other element would receive the click: <img alt="テレビCM放映中!" src="https://cw-assets.crowdworks.jp/assets/banners/fixedfooter-20200104-2000x200-5e5bc753cfe393c01c5797c1647b4fd732631e477d4308cc653f4d994f541200.png" width="1000" height="100">
...implies that the click()
to the desired element is obstructed by another element:
<img alt="テレビCM放映中!" src="https://cw-assets.crowdworks.jp/assets/banners/fixedfooter-20200104-2000x200-5e5bc753cfe393c01c5797c1647b4fd732631e477d4308cc653f4d994f541200.png" width="1000" height="100">
The obstructing element is a banner element possibly the cookies banner and you have to dismiss the banner first.
Once you dismiss the banner to identify the clickable element you need to induce WebDriverWait for the element_to_be_clickable()
and you can use either of the following Locator Strategies:
Using XPATH
:
clickable_element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='open' and starts-with(@data-path, '/public/employees')]//font[.//font[contains(., 'Läs mer')]]")))
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Upvotes: 1