1

I am having an problem with clicking an menu item that has an link with an href with selenium web drive.

<a class="a-link-normal" href="javascript:;">Fiction</a>

Here is my code:

driver.find_element_by_xpath('//*[@id="div-fiction"]/span/a').click()

This only seem to hover over the linked name and highlight it but does not trigger the javascript. I tried reading all the other solutions but it all lead to just using the click() method. Does anyone know what is wrong or a different approach to this.

1
  • did you try with js click ? Commented Nov 3, 2018 at 6:29

2 Answers 2

1

The desired element seems to be a JavaScript enabled element so you need to induce WebDriverWait for the desired element to be clickable and you can use either of the following solutions:

  • LINK_TEXT:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Fiction"))).click()
    
  • XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='a-link-normal' and contains(.,'Fiction')]"))).click()
    
Sign up to request clarification or add additional context in comments.

Comments

1

You may try this:

driver.execute_script("arguments[0].click();", webelement to click)

Comments

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.