0

I am using python+selanium first time. Learning things for now :D.

I wrote script to login and pass username/password. Able to click on button and login.

But when there is section, where CLICK TO LOAD MORE paragraph has div which has click event and I can click on that div. Check below screen for the event and code view in chrome developer tools.

Click event in Events Listener

When I try to automate this step in python+selenium, it failed.

Code

...
...
67     load_more_p = WebDriverWait(
68         driver,
69         default_timeout).until(
70             EC.element_to_be_clickable(
71                 (By.XPATH,
72                  "//p[text()='CLICK TO LOAD MORE']/.."))).click()
...
...

Get the div by selecting CLICK TO LOAD MORE paragraph and its parent.

This gives error that, div is not clickable.

Traceback

Traceback (most recent call last):
  File "/Users/mycomputer/sam.py", line 67, in <module>
    load_more_p = WebDriverWait(
  File "/Users/mycomputer/src/.tox/unittest/lib/python3.9/site-packages/selenium/webdriver/remote/webelement.py", line 94, in click
    self._execute(Command.CLICK_ELEMENT)
  File "/Users/mycomputer/src/.tox/unittest/lib/python3.9/site-packages/selenium/webdriver/remote/webelement.py", line 395, in _execute
    return self._parent.execute(command, params)
  File "/Users/mycomputer/src/.tox/unittest/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 346, in execute
    self.error_handler.check_response(response)
  File "/Users/mycomputer/src/.tox/unittest/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <div class="col-sm-12 has-text-centered cursor-pointer margin-double--top margin-double--bottom ng-tns-c178-9 ng-star-inserted">...</div> is not clickable at point (580, 752). Other element would receive the click: <div _ngcontent-rsk-c45="" class="columns banner has-text-white padding-double--left padding-double--right padding-half--top padding-half--bottom margin-none--bottom ng-tns-c45-2 ng-trigger ng-trigger-fadeInOut ng-star-inserted">...</div>
  (Session info: chrome=114.0.5735.106)
Stacktrace:
0   chromedriver                        0x000000010284ff48 chromedriver + 4226888
1   chromedriver                        0x00000001028484f4 chromedriver + 4195572
2   chromedriver                        0x000000010248cd68 chromedriver + 281960
3   chromedriver                        0x00000001024ce6e8 chromedriver + 550632
4   chromedriver                        0x00000001024cc638 chromedriver + 542264
5   chromedriver                        0x00000001024ca548 chromedriver + 533832
6   chromedriver                        0x00000001024c9918 chromedriver + 530712
7   chromedriver                        0x00000001024bdeec chromedriver + 483052
8   chromedriver                        0x00000001024bd734 chromedriver + 481076
9   chromedriver                        0x00000001024fec58 chromedriver + 748632
10  chromedriver                        0x00000001024bbf1c chromedriver + 474908
11  chromedriver                        0x00000001024bcef4 chromedriver + 478964
12  chromedriver                        0x000000010281159c chromedriver + 3970460
13  chromedriver                        0x00000001028156f0 chromedriver + 3987184
14  chromedriver                        0x000000010281b5b4 chromedriver + 4011444
15  chromedriver                        0x00000001028162fc chromedriver + 3990268
16  chromedriver                        0x00000001027ee1c0 chromedriver + 3826112
17  chromedriver                        0x0000000102832088 chromedriver + 4104328
18  chromedriver                        0x00000001028321e0 chromedriver + 4104672
19  chromedriver                        0x0000000102841f28 chromedriver + 4169512
20  libsystem_pthread.dylib             0x00000001955a026c _pthread_start + 148
21  libsystem_pthread.dylib             0x000000019559b08c thread_start + 8

is there any way to make sure what is clickable in manual also clickable in selenium automation ?

Nilesh
  • 20,521
  • 16
  • 92
  • 148

1 Answers1

1

To click on the clickable element instead of presence_of_element_located() you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following locator strategies:

  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//p[text()='CLICK TO LOAD MORE']"))).click()
    
  • 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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I also change to `element_to_be_clickable`, but same error. Please note that, `p` is not clickable, but parent of `p` which is `div` is clickable. I also change the XPATH to `//p[text()='CLICK TO LOAD MORE']` but that error as `selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element

    ...

    is not clickable at point (580, 818). Other element would receive the click: `
    – Nilesh Jun 15 '23 at 22:45
  • @Nilesh Can you find the element which obscures the click, css= `div.columns.banner.ng-star-inserted`? Does the element disappears after some time? Maybe a loader or a banner/ – undetected Selenium Jun 15 '23 at 22:49
  • Where did you get this class ? Sorry I didn't get your last comment. You want me to select the element by the `div[@class='banner ng-star-inserted` ? I also check, that component is not disappears after some time. Its stays there, and I am able to click on that. – Nilesh Jun 18 '23 at 17:47
  • @Nilesh Which is that element `//div[@class='banner ng-star-inserted.]`, is it the Cookie Banner? Shouldn't we close it first hand? – undetected Selenium Jun 18 '23 at 17:51
  • I tried `//div[contains(concat(' ', @class, ' '), ' banner ')]` but there is no div with class `banner`. – Nilesh Jun 20 '23 at 21:27
  • Let's discuss the issue in [Selenium](https://chat.stackoverflow.com/rooms/223360/selenium) room. – undetected Selenium Jun 20 '23 at 21:29