Reputation: 449
I want to check to see if a certain window is open and if it is than to proceed to log out however if it is not than to open up the widget and then logout out.
The widget is inside of another frame. I don't want to have to switch frames just to see if the widget is open if I do not have to.
My Code:
window=driver.find_element_by_id("DR44")
if window.is_displayed():
userdropdown=driver.find_element_by_id("Menu").click()
logout=driver.find_element_by_id("df456").click()
else:
LaunchMenu=driver.find_element_by_id("launch").click()
bvWidget=driver.find_element_by_id("54353sfd").click()
launch= driver.find_element_by_id("3rfs").click()
userdropdown=driver.find_element_by_id("userMdfd243l").click()
logout=driver.find_element_by_id("efdf343").click()
My error: Unable to locate element
I want to check to see if the title of the widget is found on the page if so then proceed to log out and if not open up the widget and then log out.
Upvotes: 1
Views: 2277
Reputation: 7401
You can not interact any element inside an iframe if you dont switch to iframe. First switch to iframe by driver.switch_to_frame()
and you also dont need to assign an element to variable to click to. see below:
driver.switch_to_frame(iframe)
if driver.find_element_by_id("DR44").is_displayed():
driver.find_element_by_id("Menu").click()
driver.find_element_by_id("df456").click()
else:
driver.find_element_by_id("launch").click()
driver.find_element_by_id("54353sfd").click()
driver.find_element_by_id("3rfs").click()
driver.find_element_by_id("userMdfd243l").click()
driver.find_element_by_id("efdf343").click()
To be noted: iframe is a list of iframe ids
Upvotes: 1