0

I would like to click on the dynamic URL using selenium python from a web page. I have the following HTML where 123456 is dynamic text linked to dynamic URL. I am not able to use driver.find_element_by_link_text() as text also dynamic. Can someone please help me with this?

<td class="resultsColumn"><a href="xyz.jsp?serviceID=123456=">123456</a></td>

Note: Both URL and Text also dynamic

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Mr. XYZ
  • 73
  • 2
  • 6

1 Answers1

0

To click() on the dynamic URL using Selenium and you can use either of the following locator strategies:

  • Using css_selector:

    driver.find_element(By.CSS_SELECTOR, "td.resultsColumn > a[href*='serviceID']").click()
    
  • Using xpath:

    driver.find_element(By.XPATH, "//td[@class='resultsColumn']/a[contains(@href, 'serviceID')]").click()
    

Ideally to click on the clickable element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "td.resultsColumn > a[href*='serviceID']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//td[@class='resultsColumn']/a[contains(@href, 'serviceID')]"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352