简体   繁体   中英

Selenium/Chromedriver: Can't find element in iframe

I'm using Selenium/Chromedriver via Protractor. I'm switching to an iframe, waiting for the contents to load, and then planning to manipulate elements inside it. But it's never recognizing that the contents have loaded.

browser.driver.switchTo().frame("myView");

browser.driver.wait(function() {
    return browser.driver.isElementPresent(by.id("myDiv"))
        .then(function (isPresent) {
            return isPresent;
        });
}, 20000, "Taking too long to load!");

myDiv is definitely present within 20 seconds, but wait() times out.

I've tried switching to using browser.driver.findElement(), but got the same result.

I've made sure I'm updated to Chromedriver 2.21 (which fixed an earlier error).

Any ideas what else I could be doing wrong?

ETA per comment: This is all I'm getting for an error log...

   Message:
     Error: Taking too long to load!
 Wait timed out after 20069ms
   Stacktrace:
     Error: Taking too long to load!
Wait timed out after 20069ms
==== async task ====
Taking too long to load!
    at /Users/me/Documents/My-Test/specs/myWorkflow.js:82:20
==== async task ====
    at [object Object].<anonymous> (/Users/me/Documents/My-Test/specs/myWorkflow.js:79:14)
==== async task ====
Asynchronous test function: it()
Error
    at [object Object].<anonymous> (/Users/me/Documents/My-Test/specs/myWorkflow.js:7:5)
    at Object.<anonymous> (/Users/me/Documents/My-Test/specs/myWorkflow.js:5:1)

I've gotten around similar issues by adding a sleep statement, instead of using a wait loop. In c# I would use thread.sleep(20000); for a 20 second wait. Most of mine are in the 1 to 5 second range.

To clarify: I'm suggesting removing the loop that is he is using to check for the element and instead using a simple sleep type command then interacting with the element.

In Selenium using C# I have used the following statement to provide a fixed wait time while an element loads before clicking the element. This element happens to be a link, but it can be any element

      //sleep time so UX can load
        Thread.Sleep(3000);

      //open the new  form
        By newButton = By.XPath("/dummy/xpath");
        IWebElement button = driver.FindElement(newButton);
        button.Click();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM