-2

I have the below html mark-up I am trying to access and click via python... for some reason copying the xpath and doing this is not working:

self.driver.find_element(By.XPATH, '//*`[@id="isc_8D"]/table/tbody/tr/td/table/tbody/tr/td[2]/img')`

It seems the 'name' attribute is the only unique identifier below; how could I WAIT for it to exist first, then find element by name attribute and click in python? i.e. name="isc_NXicon"

<img src="http://website:8080/DBWEBSITE/ui/sc/skins/Enterprise/images/TabSet/close.png" width="12" height="12" align="absmiddle" style="vertical-align:middle" name="isc_NXicon" eventpart="icon" border="0" suppress="TRUE" draggable="true">

I am doing the below via different element with CSS selector: But How could I do the same via html 'name attribute' for my current relevant mark-up?

WebDriverWait(self.driver, 15).until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".btn.btn-mini.btn-primary"))).click()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Dr Upvote
  • 8,023
  • 24
  • 91
  • 204
  • Did you look at [the docs](https://www.w3.org/TR/selectors/#overview)? What did you find? What have you tried? – JeffC Apr 15 '19 at 22:23

1 Answers1

1

To locate and click() on the desired element instead of using visibility_of_element_located() you need to use WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "img[name='isc_NXicon'][src$='DBWEBSITE/ui/sc/skins/Enterprise/images/TabSet/close.png']"))).click()
    
  • Using XPATH:

    WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//img[@name='isc_NXicon' and contains(@src, 'DBWEBSITE/ui/sc/skins/Enterprise/images/TabSet/close.png')]"))).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