python - Access element in default content after switching to iframe in WebDriver -


i practicing webdriver in running basic tests, , specific test send email through gmail , assert it's been received.

i'm using new version of gmail compose email button pops window asynchronously (see picture). access body of email type message, have select iframe, unable switch out , access "send" button element.

there no other noticeable frames hold "send" button, , using driver.switch_to_default_content() doesn't either. i've included snippet of code below.

driver.find_element_by_name("to").clear() driver.find_element_by_name("to").send_keys("toemailaddy@gmail.com") localtime = time.asctime( time.localtime(time.time()) ) subj = ("test - " + localtime) print(subj) driver.find_element_by_name("subjectbox").clear() driver.find_element_by_name("subjectbox").send_keys(subj) body = ("test") bodyframe = driver.find_element_by_xpath("//td[@class='ap']//iframe") driver.switch_to_frame(bodyframe) driver.find_element_by_xpath("//body[@role='textbox']").clear() driver.find_element_by_xpath("//body[@role='textbox']").send_keys(body) driver.find_element_by_xpath("/div[@role='button' , contains(text(), 'send')]").click() driver.find_element_by_link_text("inbox (1)").click() 

i can message send using actionchains send_keys(keys.control, keys,enter).perform(), figure out how access "send" button click on sake of sanity :)

gmailemail

my workaround elements have different id every test run parse page source regexp in order extract id. maybe not efficient solution works.

import re pattern = "div id=\"(:\w+)\".*send</div>" xpath = "" matchobj = re.search(pattern,driver.page_source) if(type(matchobj)!=none):     matchtuple = matchobj.groups()     if(len(matchtuple)>0):         xpath = "//*[@id=\"" + matchtuple[0] + "\"]" print("send button xpath = " + xpath) 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -