Home > Software design >  I have "no such element: Unable to locate element" error although ID is 100% correct
I have "no such element: Unable to locate element" error although ID is 100% correct

Time:01-04

I am trying to click on "OK" button on a pop up using selenium and Python but i face an error "no such element: Unable to locate element" although being sure that my id is 100% correct.

> <a  href="javascript:;" role="menuitem" id="Dialog_PAC_Menu_DXI0_T"><span >OK</span></a>

My python selenium code:

Export2 = driver.find_element(By.XPATH,'//a[@id="Dialog_PAC_Menu_DXI0_T"]')
Export2.click()

Where exactly did I go wrong, i also tried full Xpath, wait till clickable, time sleep. everything!

i would appreciate if someone can help me with it.

CodePudding user response:

Well, it looks like you found the answer and that was because your element was inside an iFrame so I will just post an answer here so others can find an easy answer if they view your question.

tmpheader = driver.find_element(By.CSS_SELECTOR, "#modal > iframe")
driver.switch_to.frame(tmpheader)
Export2 = driver.find_element(By.XPATH,'//a[@id="Dialog_PAC_Menu_DXI0_T"]')
Export2.click()

This switches our current driver that we are looking for into the first iFrame element on the page. If there is more than one iFrame you would need to check for more attributes in the first line to make sure you are looking at the correct one

CodePudding user response:

Actually that's how I solved my issue as my element was inside an iFrame as John Gordon suggested.

driver.switch_to.frame(driver.find_element(By.TAG_NAME,'iframe'))
slider = driver.find_element(By.XPATH,"//*[contains(@id,'_xaf_dviImportExportFormat_Edit_dropdown_DD_B-1Img')]").click()
  • Related