0

Seem to be getting this error when trying to click view more until the end of the page (until I don't see the view more option), but getting this error message

ElementClickInterceptedException               14 wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'select2-result-label'))).click()
     15 while True:
---> 16     wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'view_more'))).click()
     17     try:
     18         element = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'view_more')))
ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (231, 783)
  (Session info: chrome=78.0.3904.108)

This is the code I have

while True:
    wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'view_more'))).click()
    try:
        element = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'view_more')))
        element.click()
    except TimeoutException:
        break

Here is the html from the site

<a class="view_more" href="javascript:void(0);" onclick="_search('0')">VIEW MORE ...</a>

This is the website

page_link = 'http://beta.compuboxdata.com/fighter'
Emm
  • 2,367
  • 3
  • 24
  • 50
  • This question may be helpful: https://stackoverflow.com/questions/38327049/check-if-element-is-clickable-in-selenium-java – DMart Dec 04 '19 at 17:47
  • that site's got some whacky javascript and needs fixin'. Not sure why, but the first thing it does is post data... and the link is not working for me. (using Chrome) – pcalkins Dec 04 '19 at 20:53

1 Answers1

-1

Firstly, Why do you have the same line of code duplicated in two different ways?

wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'view_more'))).click()

is functionally equivalent to:

try:
    element = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'view_more')))
    element.click()
except TimeoutException:
    break

save for handling the timeout exception. I would just remove the first line, as I don't see the point in it. On to your actual issue, see the answer to this stack overflow question: https://stackoverflow.com/a/44916498/3715974

My best guess is that it's due to a javascript/ajax call that's loading contents onto the page and the view more button isn't available immediately, causing your code to panic. Read through that answer and it may give you more insight, but you could also try simply catching that exception, delaying for a small period of time and trying again.

TheKewlStore
  • 304
  • 1
  • 6
  • Could be mistaken, but added the first line because I want to keep clicking view more until the end of the page – Emm Dec 04 '19 at 18:19
  • That block is encapsulated in a while True loop, which will already do that by running the click line indefinitely. No need to do 2 clicks per loop, in fact that will open you up to a bug because the first "click" in the loop is not handling timeout exceptions and could cause an error. – TheKewlStore Dec 04 '19 at 18:24