I have recently switched from selenium to nodriver for speed and stealth reasons. I am having trouble accessing elements inside an iframe even though material on this site and elsewhere says that 'Using nodriver, you don't need to switch to iframe to interact with it. nodriver's search methods automatically switch to iframe if the searched text/element is not found.'
My experience is quite different. Despite researching every thing I can find and many attempts, I cannot seem to access an embedded element. In the code below I gain access to a website and advance to the page with the iframe. I then successfully access an element on the page (demo = await page.find...), but outside the iframe (to confirm that the page is correct). The attempt to find the element (address_line_1 = await page.find...) then fails and throws off a 'Time ran out while waiting for text' error.
async def b_main_line_processing():
driver = await uc.start() # maximize=True) # Start a new Chrome instance
await driver.main_tab.maximize()
page = await driver.get(passed_website, new_tab=False, new_window=False) # Open website
# Enter Log In Id & Password
field_to_find = await page.find('//*[@id="p_lt_PageContent_Login_LoginControl_ctl00_Login1_UserName"]')
await field_to_find.send_keys(name)
password_entry = await page.find('//*[@id="p_lt_PageContent_Login_LoginControl_ctl00_Login1_Password"]')
await password_entry.send_keys(password)
# Log In Button Press
button_to_press = await page.find('//*[@id="p_lt_PageContent_Login_LoginControl_ctl00_Login1_LoginButton"]')
await button_to_press.click()
# Advance to iframe page - Open up drop down and make selection
option = await page.find('//*[@id="p_lt_Header_MyProfilePages_lblMemberName"]')
await option.click()
profile = await page.find('// *[ @ id = "p_lt_Header_MyProfilePages_lnkEditProfile"]')
await profile.click()
# Arrived on iframe page; find option above iframe to prove we are on the right page
demo = await page.find("/html/body/form/div[4]/header/div/div[2]/nav/ul/li[8]/a")
print("button found")
# That worked so look for element embedded in the iframe
try:
sleep(2)
address_line_1 = await page.find\
("/html/body/form/div[4]/div[2]/div/div/div/div[2]/ng-form/div[1]/div[5]/div/div[1]")
except Exception as e:
print("Iframe error:", e)
driver.stop()
a_main_processor()
Relevant portion of html:
> <iframe id="module" class="moduleIframe" src="/CMSModules/CHO/Roster/Roster.aspx#/edit/2137597" frameborder="0" scrolling="no" style="height: 5458px;"></iframe>Blockquoteenter code here
Any ideas greatly appreciated.