4
    <dependency>
        <groupId>com.github.detro</groupId>
        <artifactId>phantomjsdriver</artifactId>
        <version>1.2.0</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.0.1</version>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-support</artifactId>
        <version>3.0.1</version>
    </dependency>

When I'm using code below with phantomjsdriver, I'm not able to find element via css selector - table.b3id-widget-table.b3-widget-table after switching to Frame. The element is located inside iframe.

Meanwhile I'm able to find this element using Firefox or Chrome binaries with same code. It seems that after switching to frame phantomjs is not enable to find any elements inside iframe. Any clue ?

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("standalone-container-main-widgetIframe")));
driver.switchTo().frame("standalone-container-main-widgetIframe");
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("table.b3id-widget-table.b3-widget-table")));

Another answers suggest to add following options in case if iframes are on the another origin.

String [] phantomJsArgs = {"--ignore-ssl-errors=true", "--ssl-protocol=any", "--web-security=false"};
dCaps.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARGS, phantomJsArgs);
dCaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomJsArgs);

But it does not help for me. The weirdest thing that sometimes it worked few times, 1 time from 50 attempts somehow. I changed different timeouts, implicit awaits, explicit awaits - nothing helps, even wait for 3-4 minutes. Seems it is not the timing issue. Also I noticed that my iframe has no src attribute, maybe that's the issue

 <iframe frameborder="0" src="about:blank" id="standalone-container-main-widgetIframe">

Also I took screenshot using PhantomJs and looks like the page is loaded successfully including nested iframes, screenshot is trimmed for some reason thought.

user12384512
  • 3,362
  • 10
  • 61
  • 97
  • 1
    @Igor updated question. Fixed typo. Was copy-pasting markup, actually this markup is generated by Google. It's Google Wallet table with orders – user12384512 Dec 08 '16 at 18:16
  • 1
    http://stackoverflow.com/questions/24247490/find-elements-inside-forms-and-iframe-using-java-and-selenium-webdriver –  Dec 08 '16 at 19:29
  • 1
    @user12384512 I cannot reproduce your problem using `selenium-server-standalone-3.0.1` and `phantomjs 2.1.1` for Windows. I get the `iframe` with `By.cssSelector("table.b3id-widget-table.b3-widget-table")`, which loads the page dynamically with jQuery after page load and I can even execute some javascript and change the `iframe` body color. I can provide my example (which is based on your code) if you want. – Christos Lytras Dec 10 '16 at 16:31
  • 1
    @ChristosLytras I think that our code is very similar. I did not try to reproduce it in sandbox. Eventually I had to use FF binaries instead of PhantomJs. If only you have Google Wallet Merchat account, you could try to parse same page yourself. Maybe the difference between your markup and Google markup that elements are added dynamically inside iframe using javascript by Google. – user12384512 Dec 13 '16 at 09:58
  • Possible duplicate of [Find elements inside forms and iframe using Java and Selenium WebDriver](https://stackoverflow.com/questions/24247490/find-elements-inside-forms-and-iframe-using-java-and-selenium-webdriver) – kenorb Aug 23 '17 at 16:14
  • Duplicate of: [How to switch between frames in Selenium WebDriver using Java](https://stackoverflow.com/q/10879206/55075). – kenorb Aug 23 '17 at 16:20

1 Answers1

1

Have you tried ...

driver.FindElement(By.Name("standalone-container-main-widgetIframe"));
string frameHTML = driver.SwitchTo().Frame("standalone-container-main-widgetIframe").PageSource;
doc.LoadHtml(frameHTML);

So this way you can see your frame html as well. You will need to use htmlagilitypack as well for this...

Bulut Kartal
  • 83
  • 2
  • 20