0

Is there a way to perform a wait.Until by somehow searching the element from another element, rather than from the whole driver?

example:

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSec));

IWebElement element = wait.Until(ExpectedConditions.ElementExists(by));

I cannot modify the 'by' to be too specific and when it is searched under the driver and gets the wrong element.

IWebElement element = wait.Until(drv => drv.FindElement(by));

this option also searches under the driver. I want something like this:

public static IWebElement WaitElement(this IWebElement webElement, IWebDriver driver, By by, int timeoutInSec = 5)
    {
        try
        {
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSec));
                IWebElement element = wait.Until(webElement.FindElement(by));
        }

When I try to write this code I get this error:

enter image description here

Daphne
  • 21
  • 6
  • There's three [types](http://toolsqa.com/selenium-webdriver/implicit-explicit-n-fluent-wait/). See [wait until an element is present](https://stackoverflow.com/questions/6992993/selenium-c-sharp-webdriver-wait-until-element-is-present) – lloyd May 01 '18 at 04:44
  • What you've done is actually correct. You can find child element from patent element. – Magesh May 01 '18 at 04:55
  • What I have written (last code) is not 'legal' and is not accepted – Daphne May 03 '18 at 00:05
  • Use By.CssSelector("#parentId #childId"); – Koja May 04 '18 at 17:30
  • 1
    Daphne, did you ever find a solution to this? I'm encountering the same issue where I'm looping through found elements and need to wait on a sub element of each element. – user1970794 Nov 09 '18 at 21:45

1 Answers1

0

It may be late, but hopefully will help someone else. Just change the syntax of your last line in the 3rd option to the following:

IWebElement element = wait.Until(d => webElement.FindElement(by));
user1106591
  • 476
  • 3
  • 12