0

I'm using following code for find the iframe in a web page

string win = diver.CurrentWindowHandle;
driver.switchTo().Window(win);
driver.switchTO().defautContent();

Then I tried with the following things but still I got the NO frame found error.

driver.switchTo().Frame(1); (or)
driver.switchTo().Frame(0);
driver.switchTo().Frame(driver.findelement(by.id(By.xpath("//xpath of d frame")))
driver.switchTo().Frame(driver.findelement(by.id(By.tagname(iframe)))
driver.switchTo().Frame(driver.findelement(by.id(By.className(classnamehere)))

Please click here to view the HTML structure

User
  • 1
  • 5
  • can you try `driver.switchTo.Frame("contentIFrame0")` – NarendraR Dec 14 '17 at 06:35
  • @NarendraR yes .. I already tried that too.. same its throwing NosuchFrameException – User Dec 14 '17 at 06:38
  • can share the site URL – NarendraR Dec 14 '17 at 06:39
  • it will open inside the client machine only – User Dec 14 '17 at 06:41
  • I guess there is some glitch while you are switching first window and then frame. is is opening 2 windows ? and you are switching in second window and the switching in iframe in that seconds window ? – NarendraR Dec 14 '17 at 06:46
  • its not opening two separate windows .first step I'm opening the record and click on button which is available in new window.after clicking its generating our target iframes in the same window itself – User Dec 14 '17 at 06:53
  • then why you are switching the window. just comment the switching window code and try – NarendraR Dec 14 '17 at 06:55
  • Possible duplicate of [How can I select a html element no matter what frame it is in in selenium?](https://stackoverflow.com/questions/47770144/how-can-i-select-a-html-element-no-matter-what-frame-it-is-in-in-selenium/47771879#47771879) – undetected Selenium Dec 14 '17 at 06:57
  • @NarendraR still there is no luck. – User Dec 14 '17 at 07:09
  • @DebanjanB I dono why you make this question as duplicate.That mentioned question is belongs to python.But its c# and more over I tried all the ways but I didn't achieve. – User Dec 14 '17 at 07:12
  • You need to share the relevant `HTML` for SO volunteers to help you out. Switching frames doesn't needs the `window_handles` as such. – undetected Selenium Dec 14 '17 at 07:18
  • @DebanjanB I already added the html structure in the question itself. – User Dec 14 '17 at 07:21
  • Instead of adding snapshots of `html structure` can you add the `HTML` as a formatted text? Which `iframe` do you want to switchover? – undetected Selenium Dec 14 '17 at 07:25
  • @DebanjanB I completely agree your point to post a code instead of image.But I'm not able to copied the code from client machine.In client machine there is no internet connection.so tat I posted as a image. I want to shift **contentIFrame1** – User Dec 14 '17 at 07:30

1 Answers1

0

Let us analyze whats happening in your code :

  • Code Attempt 1:

    string win = diver.CurrentWindowHandle;
    driver.switchTo().Window(win);
    

    All the frames remains attached to the same windowHandle. So driver.switchTo().Window(win); is not a choice.

  • Code Attempt 2:

    driver.switchTo().Frame(1);
    driver.switchTo().Frame(0);
    

    As we are not sure of the loading sequence of the frames, trying to switch frames through index may not help us.

  • Code Attempt 3:

    driver.switchTo().Frame(driver.findelement(by.id(By.xpath("//xpath of d frame")))
    

    This should have worked provided we had supplied a valid and unique xpath of the frame.

  • Code Attempt 4:

    driver.switchTo().Frame(driver.findelement(by.id(By.tagname(iframe)))
    

    This will try to switch to the first available iframe which may not be the intended one or visible at all. Hence Fails.

  • Code Attempt 5:

    driver.switchTo().Frame("contentIFrame0");
    

    This option wouldn't work straight away as the visibility attribute is set to hidden

  • Code Attempt 6:

    driver.switchTo().Frame("contentIFrame1");
    

    This option must work but from the HTML which you have shared the WebElements are not clear.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I use the following codes `driver.SwitchTo().ParentFrame();driver.SwitchTo().defaultContent();driver.findelements(by.tagname("iframe"))` . Now Im getting 32 digit unique frame ids. – User Dec 14 '17 at 09:55
  • Is possible to get the elements which is inside the frame, by using this frame ids? – User Dec 14 '17 at 09:57