1

I am automating a function where the user needs to click on the link highlighted in the below link.

HTML

I tried a contains on the xpath which is //*[@id="lc"], and an onclick option from Here neither of which work and error with the element doesn't exist error.

I know I am in the right iframe, because when using the xpath with no contains the script clicks the first xpath link with no issue.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
polishfreak
  • 49
  • 1
  • 9
  • could you be more specific about what you are trying to do here? this HTML structure if pretty complex, and obfuscated, so it's hard to figure just where that selected td is located. if the id is not unique, then we need to find something else...is there something unique in the method that's being called in the onclick? – Breaks Software Jan 15 '19 at 01:33
  • Please share your code between code tags and the relevant html using the snippet tool available via [edit]. Also, include the url if possible. – QHarr Jan 15 '19 at 06:53

3 Answers3

0

I have not use Selenium with Python, but I have with java, and in Java you have to use simple quote (') instead the double quote ("), or you can just a simpler locator id=lc without any quotes, if you're sure the ID is correct this should work.

israelss
  • 322
  • 3
  • 6
  • Unfortunately the xpath is the same on all td elements, so this is why I was looking for the onclick method as then I can call out this specific link. – polishfreak Jan 14 '19 at 20:57
  • Oh ok, in that case I use Katalon Recorder (https://chrome.google.com/webstore/detail/katalon-recorder/ljdobmomdgdljniojadhoplhkpialdid) , it is a lot better than Selenium IDE to get the right xpath. – israelss Jan 14 '19 at 22:10
  • "xpath is the same on all td elements"...are you saying that all td elements have an "id" attribute of "lc"? that would be BAD HTML. – Breaks Software Jan 15 '19 at 01:30
0

i have done this in java hope you find the answer yes in static or in dynamic tables the id will be the same but if you try using absolute xpath this are two absolute path of the table element resides each other in first row

/html[1]/body[1]/section[1]/section[1]/div[1]/data[1]/div[1]/div[4]/div[1]/div[1]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]

/html[1]/body[1]/section[1]/section[1]/div[1]/data[1]/div[1]/div[4]/div[1]/div[1]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[2]/div[1]

This are the relative xpath of the same elements

//a[contains(text(),'AF17OT41603')]

//div[@id='1547533504703-0-uiGrid-000C-cell']//div[@class='ui-grid-cell-contents ng-binding ng-scope'][contains(text(),'AKSHAY PATIL')]

Table

akshay patil
  • 670
  • 7
  • 20
0

To click() on the desired element as the element is a dynamic element you have 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.EMROtherEpsEven>table tr>td.EMROtherEpsEven#lc[onclick*='Hemoglobin']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//td[@class='EMROtherEpsEven']/table//tr/td[@class='EMROtherEpsEven' and @id='lc'][contains(@onclick, 'Hemoglobin')]"))).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