Reputation: 351
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&rc_id=181786&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.
Upvotes: 0
Views: 456
Reputation: 33384
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)
Upvotes: 2