Reputation: 557
My python Selenium program could not find the frame in which I think the web-element is residing. Please let me know if I am doing something wrong. Thank you.
# switch back to main window
driver.switch_to.window(main_window_handle)
time.sleep(5)
driver.switch_to.frame("header");
driver.find_element_by_id("a_1").click()
time.sleep(10)
# switch back to main window
driver.switch_to.window(main_window_handle)
time.sleep(5)
driver.switch_to.frame("contents"); ***<----- failed here***
time.sleep(5)
driver.switch_to.window("itreecontrol");
time.sleep(5)
# Click on desired item
driver.find_element_by_xpath("//div/a/span/span/span").click()
===============================
Additional issue: Cannot find element on popped-up window
# switch back to main window
driver.switch_to.window(main_window_handle)
time.sleep(5)
driver.switch_to.frame("header");
driver.find_element_by_id("a_1").click()
time.sleep(10)
# Go to correct frame first
driver.switch_to.default_content()
driver.switch_to.frame("contents");
driver.switch_to.frame(driver.find_element_by_tag_name("iframe"));
time.sleep(5)
# Click on plus icon to pop up a window
driver.find_element_by_xpath("//div/a/span/span/span").click()
# Enter your info in this text-field element in the popped-up window
# (failed to find "unitName-inputEl" here)
driver.find_element_by_id("unitName-inputEl").clear() <--- failed here
# switch back to main window
driver.switch_to.window(main_window_handle)
# Click on 'Firewall' panel
time.sleep(5)
driver.switch_to.frame("header");
driver.find_element_by_id("a_1").click()
time.sleep(10)
# switch to default content
driver.switch_to.default_content()
# Go to the correct frame first
driver.switch_to.frame("contents");
driver.switch_to.frame("itreecontrol");
time.sleep(5)
# Click on plus-box icon to display pop-up
driver.find_element_by_xpath("//div/a/span/span/span").click()
driver.find_element_by_id("unitName-inputEl").clear()
#driver.find_element_by_id("unitName-inputEl").send_keys("tz400")
wait(driver, 10).until(EC.element_to_be_clickable((By.ID, "unitName-inputEl"))).send_keys('tz400')
Upvotes: 0
Views: 599
Reputation: 52665
After switching to <iframe id="header">
you need to switch back to default content to be able to switch to <iframe id="contents">
try:
driver.switch_to.frame("header");
driver.find_element_by_id("a_1").click()
time.sleep(10)
driver.switch_to.default_content()
time.sleep(5)
driver.switch_to.frame("contents")
driver.switch_to.frame("itreecontrol")
To handle input
field you can try to use ExplicitWait
as below:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
wait(driver, 10).until(EC.element_to_be_clickable((By.ID, "unitName-inputEl"))).send_keys('tz400')
Upvotes: 1