2

I am trying to switch to the previous frame.

In my code

  1. I switch to a frame (BRCT1Frame),
  2. Click a button that opens a new window
  3. Switch to a new window
  4. Switch to the frame inside of the window
  5. Insert data & save which closes both the window and frame

However, there is a frame that is before the BRVT1Frame that I need to switch to.

Here is My Code:

BRT1Frame=driver.switch_to_frame(driver.find_element_by_tag_name("iframe"))
    buttons=driver.find_elements_by_css_selector("button")
    for button in buttons:
        if button.text.strip()=="Create Community":
            button.click()

    #A new pop up window causes me to switch windows
for handle in driver.window_handles:
    BRT=driver.switch_to_window(handle)
    print(BRT)

#then I switch frames
driver.switch_to_frame(driver.find_element_by_class_name("FormDialogIFrame"))   
driver.find_element_by_id("CommunityFormCommunityNameTextBox").send_keys("1st MEB STAFFEX")

save=driver.find_element_by_id("CommunityFormSaveButton").click()
#that popup closes now I have to switch to another frame

The frame I am trying to switch to code:

<iframe role="presentation" 
class="x-component x-window-item x-component-default"
src="/brvt?lang=en_US&amp;owf=true&amp;themeName=a_default&amp;
themeContrast=standard&amp;themeFontSize=12" 
name="{&quot;id&quot;:&quot;778a1259-bc80-602e-c0ad-16a3f9220516&quot;,&quot;containerVersion&quot;:&quot;7-GA&quot;,&quot;webContextPath&quot;:&quot;/owf&quot;,&quot;preferenceLocation&quot;:&quot;https://www.url,com;,&quot;relayUrl&quot;:&quot;https://url.com/55js/even/rpc_relay.uncompressed.html&quot;,&quot;lang&quot;:&quot;en_US&quot;,&quot;currentTheme&quot;:{&quot;themeName&quot;:&quot;a_default&quot;,&quot;themeContrast&quot;:&quot;standard&quot;,&quot;themeFontSize&quot;:12},&quot;55f&quot;:true,&quot;layout&quot;:&quot;desktop&quot;,&quot;url&quot;:&quot;/brvt&quot;,&quot;guid&quot;:&quot;260f0022-66de-a78b-3ce8-8de63a3bdbec&quot;,&quot;version&quot;:1,&quot;locked&quot;:false}" 
id="{&quot;id&quot;:&quot;778a1259-bc80-602e-c0ad-16a3f9220516&quot;}" 
frameborder="0"></iframe>

I have tried to do this:

driver.switch_to_frame(driver.find_element_by_tag_name("iframe"))

this worked but when I tried to click a drop down menu inside of the frame:

driver.find_element_by_css_selector("#OYk3vd6NKj1jbrnew > td.sub_item_text").click()

I have also tried:

 driver.switch_to_frame(driver.find_element_by_id("{&quot;id&quot;:&quot;778a1259-bc80-602e-c0ad-16a3f9220516&quot;}")

I get an error that states that it is unable to locate the element. Suggestions?

1 Answer 1

2

If you just want to locate exact frame that you specified, then try:

required_frame = driver.find_element_by_xpath('//iframe[@role="presentation"]')
driver.switch_to_frame(required_frame)

or even more specific:

required_frame = driver.find_element_by_xpath('//iframe[@role="presentation"][@class="x-component x-window-item x-component-default"]')
driver.switch_to_frame(required_frame)

Does this advise was helpful?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.