0

I'm trying to click on a javascript:void(0) href in selenium python however it isn't working out for me. I have tried using the following:

element = WebDriverWait(driver, 
20).until(EC.presence_of_element_located((By.XPATH, "//*[@id='32de8167-e65c- 
436a-9a6e-2561854c2c3c']")))
driver.execute_script("arguments[0].click();", element)

I get the following error:

raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

When I'm using:

driver.find_element_by_xpath("//*[@id='32de8167-e65c-436a-9a6e-2561854c2c3c']").click()

I get the following error:

Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='32de8167-e65c-436a-9a6e-2561854c2c3c']"}

When I try to click on a javascript:void(0) with onlick inside the href link it is working but in this case it isn't working out for me.

In this case:

<a id="3ca786c0-2a8d-4055-b6ce-800d77c6ad59" href="javascript:void(0);">Word nu member.</a>

1 Answer 1

1

The second approach gives an error that is unrelated to the javascript. It cannot find the element. That is not strange, given the id in your xpath does not match that in the html.

Sign up to request clarification or add additional context in comments.

3 Comments

I'm using copy xpath in google chrome, and I know that it is giving the error but I'm using the same id for the first approach.
Could it be that the ID is generated uniquely on each request? In that case, you should find another identifier. Both approaches (timeout, element not found) indicate that the problem is with the selector, if I understand your question correctly.
Oh, yes I see now that every time I visit the website I get another ID. Thanks this helped me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.