1

I am new to selenium and trying to automate some web click using selenium and python

There is a link as per below, which opens up dialogue box

<li id='upFol'>
<a href='#' title='documents'></a>
.....
</li>

I have below code in python

upload = WebDriverWait(driver,5).until(EC.presence_of_element_located((By.XPATH,"//*[@id='upFol']/a")))
upload.click()

this finds the element and can see the click but dialogue box doesn't get opened

Is there way to handle these kind of scenarios

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
user12073359
  • 289
  • 1
  • 11

1 Answers1

0

Instead of presence_of_element_located() 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, "li#upFol > a[title='documents']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//li[@id='upFol']/a[@title='documents']"))).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
  • hi, this worked for me. But at a later stage I am doing the same for another button `WebDriverWait(driver, 2).until(EC.element_to_be_clickable((By.XPATH,"//*[@id='submit']"))).click()` but it gives me exception `TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException`. I tried putting timer sleep as well. do you have any tips that I can look into? thanks – user12073359 Dec 10 '20 at 00:11