1

I have the following snippet of code:

var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
            wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("loginButton")));
            driver.FindElementById("loginButton").Click();

            wait.Until(JavascriptInjector.GetDocumentReadyState(driver) == expectedReadyState);

JavascriptInjector.GetDocumentReadyState(driver) executes return document.readyState in the Chrome browser and returns the value as a string. expectedReadyState is of type string. However, I am getting the following error:

"The type argument cannot be inferred from the usage."

Any suggestions as to how to get past this error?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
orajestad9
  • 261
  • 1
  • 2
  • 10
  • https://stackoverflow.com/questions/6992993/selenium-c-sharp-webdriver-wait-until-element-is-present – iSR5 Feb 10 '18 at 01:32
  • Please read [ask], especially the part about [mcve] (MCVE), and [How much research effort is expected?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) This will help you debug your own programs and solve problems for yourself. If you do this and are still stuck you can come back and post your MCVE, what you tried, and the execution result including any error messages so we can better help you. Also provide a link to the page and/or the relevant HTML. – JeffC Feb 10 '18 at 03:47
  • Can you update the question with your Manual Step which you are trying to Automate? – undetected Selenium Feb 10 '18 at 11:02

1 Answers1

2

The Until method of WebDriverWait does not take a bool as an argument. It takes a function taking an IWebDriver, and returning an inferrable type (of which bool is one). What you want is something like the following:

wait.Until((d) => { return JavascriptInjector.GetDocumentReadyState(d) == expectedReadyState; });
JimEvans
  • 27,201
  • 7
  • 83
  • 108
  • Thanks for this. My wait is working properly now with this update. I'll also go back and re-read the How to Ask documentation as suggested above. – orajestad9 Feb 12 '18 at 21:23