Phantom swithToFrame not working

    <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 use the code below with phantomjsdriver, I can not find the element through the css selector - table.b3id-widget-table.b3-widget-tableafter switching to Frame. The element is located inside the iframe.

In the meantime, I can find this element using Firefox or Chrome binaries with the same code. It seems that after switching to the framefan it does not allow to find any elements inside the 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")));

Other answers suggest adding the following parameters if iframes are in a different source.

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);

. , , 1 50 -. , , - , 3-4 . , . , iframe src, ,

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

PhantomJs , , , - .

+4
1

...

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

, html. htmlagilitypack ...

+1

Source: https://habr.com/ru/post/1662873/


All Articles