Untitled

 avatar
unknown
plain_text
9 months ago
1.0 kB
12
Indexable
public void ClickProjekt()
{
    var by = By.CssSelector("#selection-project-button > a");
    IWebElement el = null;

    driver.SwitchTo().DefaultContent();

    try
    {
        el = new WebDriverWait(driver, TimeSpan.FromSeconds(5)).Until(d => d.FindElement(by));
    }
    catch { }

    if (el == null)
    {
        foreach (var frame in driver.FindElements(By.CssSelector("iframe,frame")))
        {
            driver.SwitchTo().Frame(frame);
            var list = driver.FindElements(by);
            if (list.Count > 0) { el = list[0]; break; }
            driver.SwitchTo().ParentFrame();
        }
    }

    if (el == null)
        throw new NoSuchElementException("Could not find '#selection-project-button > a' in the page or any iframes.");

    ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView({block:'center',inline:'center'});", el);
    try { el.Click(); }
    catch { ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", el); }

    driver.SwitchTo().DefaultContent();
}
Editor is loading...
Leave a Comment