0

I am trying to use Selenium in Python to click on a link to a report on a web page. I have it working up to the point where it opens the page that the report is on, but I am having trouble actually clicking that specific report.

The page has a list of reports all with the same class. This is what I get when I inspect that specific report for example:

<a class="rpt" href="reportConfigRedirect.asp?action=filter&amp;rc_id=181786&amp;letter=">Run with new filters</a>

I have tried:

driver.find_element_by_xpath("xpath")

and this doesn't seem to work, it doesn't do anything once it gets to that page with the report.

3
  • 1
    have you tried, right clicking, inspecting the elemnent and then copying the xpath? Commented Jun 3, 2019 at 18:22
  • Yes, I did that and pasted the xpath to my code above, it did not do anything when it got to that point Commented Jun 3, 2019 at 18:26
  • You may need to add wait(s) for that element. Can you share the xpath that you used? Commented Jun 4, 2019 at 6:10

1 Answer 1

2

Induce WebdriverWait and element_to_be_clickable.Use the following Xpath.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


element=WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//a[@class='rpt'][contains(.,'Run with new filters')]")))
element.click()

If unable to click using Webdriver try use javascript executor.

element=WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//a[@class='rpt'][contains(.,'Run with new filters')]")))
driver.execute_script("arguments[0].click();",element)

EDITED


element=WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//a[contains(.,'Run with new filters')]")))
driver.execute_script("arguments[0].click();",element)

OR

element=WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//a[contains(@hef,'reportConfigRedirect.asp?action=filter')][contains(.,'Run with new filters')]")))
driver.execute_script("arguments[0].click();",element)
Sign up to request clarification or add additional context in comments.

1 Comment

Great thanks, the second option worked and was able to click the report now. There is a final link now to the report and I tried to apply the same to this but now this one isn't clicking. This is the inspect code : <a href="reportConfigRedirect.asp?action=filter&amp;rc_id=181786">Run with new filters</a>

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.