GVKun编程网logo

Selenium-IE 11中的NoSuchWindowException(selenium ie options)

24

以上就是给各位分享Selenium-IE11中的NoSuchWindowException,其中也会对seleniumieoptions进行解释,同时本文还将给你拓展c#–.NETSeleniumNo

以上就是给各位分享Selenium-IE 11中的NoSuchWindowException,其中也会对selenium ie options进行解释,同时本文还将给你拓展c# – .NET Selenium NoSuchElementException; WebDriverWait.Until()不起作用、java – 在Selenium中避免NoSuchElementException的最好方法是什么?、OpenQA.Selenium.NoSuchElementException:没有这样的元素:无法定位元素 C# 按类查找、org.openqa.selenium.NoSuchElementException的实例源码等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

Selenium-IE 11中的NoSuchWindowException(selenium ie options)

Selenium-IE 11中的NoSuchWindowException(selenium ie options)

我正在尝试使用IE11中的selenium来自动化网页。我已将保护模式设置设为相同级别,并且缩放级别为100%。在运行测试时,它会打开网站,但是之后会给出异常。下面是使用的代码。

   File file = new File("C:\\Users\\Desktop\\IEDriverServer.exe");   System.setProperty("webdriver.ie.driver", file.getAbsolutePath() );          DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();   capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,   true);    WebDriver driver = new InternetExplorerDriver(capabilities);   driver.get("http://www.google.com");

和异常stacktrace

Started InternetExplorerDriver server (32-bit)2.39.0.0Listening on port 38122Jul 11, 2014 1:50:02 PM org.apache.http.impl.client.DefaultRequestDirector tryExecuteINFO: I/O exception (java.net.SocketException) caught when processing request: Software caused        connection abort: recv failedJul 11, 2014 1:50:02 PM org.apache.http.impl.client.DefaultRequestDirector tryExecuteINFO: Retrying requestException in thread "main" org.openqa.selenium.NoSuchWindowException: Unable to find element on   closed window (WARNING: The server did not provide any stacktrace information)Command duration or timeout: 18 millisecondsBuild info: version: ''2.39.0'', revision: ''ff23eac'', time: ''2013-12-16 16:12:12'' System info: host: ''Neeraj'', ip: ''10.136.180.161'', os.name: ''Windows 7'',  s.arch: ''amd64'',      os.version: ''6.1'', java.version: ''1.7.0_60''  Session ID: ab6edd65-8a66-41fa-be46-56fba7dbdfc9Driver info: org.openqa.selenium.ie.InternetExplorerDriver Capabilities [{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0,                          ignoreZoomSetting=false,                                  enablePersistentHover=true, ie.ensureCleanSession=false, browserName=internet explorer, enableElementCacheCleanup=true,   unexpectedAlertBehaviour=dismiss, version=11, ie.usePerProcessProxy=false, cssSelectorsEnabled=true,   ignoreProtectedModeSettings=true, requireWindowFocus=false,  handlesAlerts=true, initialBrowserUrl=http://localhost:38122/, ie.forceCreateProcessApi=false, nativeEvents=true, browserAttachTimeout=0, ie.browserCommandLineSwitches=, takesScreenshot=true}]      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)      at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)      at java.lang.reflect.Constructor.newInstance(Unknown Source)      at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)      at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307) at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:348) at org.openqa.selenium.By$ById.findElement(By.java:220) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299) at Test1.main(Test1.java:27)

有关如何解决此问题的任何建议。

答案1

小编典典

首先,不要使用

capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);

因为您已经设置了保护模式设置。对于您所看到的问题,应该是由于缺少注册表设置而导致的,这些注册表设置是作为在IE11中运行测试的先决条件而添加的:

https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-
configuration

c# – .NET Selenium NoSuchElementException; WebDriverWait.Until()不起作用

c# – .NET Selenium NoSuchElementException; WebDriverWait.Until()不起作用

我们有一个.NET 4.5,MVC,C#项目.我们正在使用Selenium进行UI测试,测试会在我们有wait.Until()的行上间歇性地失败.一个这样的例子是:

NoSuchElementException was unhandled by user code
An exception of type 'OpenQA.Selenium.NoSuchElementException' occurred in WebDriver.dll but was not handled in user code
Additional information: Unable to locate element: {"method":"css selector","selector":"#assessment-472 .status-PushedToSEAS"}

它就在这里抛出:

Thread.Sleep(600);
wait.Until(drv => drv.FindElement(By.CssSelector("#" + assessmentQueueId + " .status-PushedToSEAS")));

我可以看到浏览器打开,我看到它到达那一点,我可以检查元素以查看元素是否存在.它的id完全正确.

我们有这个问题很多,到目前为止解决方案是在它前面抛出Thread.Sleep(600)(或类似的时间). wait.Until()的重点是不必这样做,这使我们的测试套件变得非常长.另外,正如您在上面的示例中所看到的,有时我们甚至在将Thread.Sleep()放在它前面之后也会遇到问题,我们必须延长时间.

为什么.NET Selenium的WebDriver.Until()不起作用,并且有一种不同的方式来做同样的事情而不需要等待一段时间?同样,问题是间歇性的,这意味着它有时只会发生,它可能发生在任何数量的wait.Until()语句中,而不仅仅是显示的那个!

编辑:

这是一个类变量.
私人WebDriver等等;

它实例化如下:

this.wait = new webdriverwait(driver,TimeSpan.FromSeconds(10));

解决方法

我决定不使用webdriverwait.Until(),而是在主驱动程序上使用隐式等待:

driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));

为了给我这个想法,我在一个不同的问题上充分赞扬了this answer.

java – 在Selenium中避免NoSuchElementException的最好方法是什么?

java – 在Selenium中避免NoSuchElementException的最好方法是什么?

我在Selenium WebDriver中使用 Java编写了几个测试用例,并在网格(集线器和多个节点)上执行它们.我注意到,由于NoSuchElementException,几个测试用例失败.什么是避免NoSuchElementException和确保元素总是找到最好和最强大的方法?

解决方法

你永远不能确定该元素将被发现,实际上这是功能测试的目的 – 告诉你页面上是否有任何改变.但有一点肯定有帮助的是添加等待通常导致NoSuchElementException的元素
webdriverwait wait = new webdriverwait(webDriver,timeoutInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id<locator>));

OpenQA.Selenium.NoSuchElementException:没有这样的元素:无法定位元素 C# 按类查找

OpenQA.Selenium.NoSuchElementException:没有这样的元素:无法定位元素 C# 按类查找

如何解决OpenQA.Selenium.NoSuchElementException:没有这样的元素:无法定位元素 C# 按类查找?

Message: 
Test method CFSSOnlineBanking.SmokeTests.Transferdisplay threw exception: 
OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#menuLeftRailContainer > div:nth-child(1) > div:nth-child(3)"}
  (Session info: chrome=91.0.4472.164)

Stack Trace: 
RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
RemoteWebDriver.Execute(String driverCommandToExecute,Dictionary`2 parameters)
RemoteWebDriver.FindElement(String mechanism,String value)
RemoteWebDriver.FindElementByCssSelector(String cssSelector)
<>c__displayClass23_0.<CssSelector>b__0(ISearchContext context)
By.FindElement(ISearchContext context)
RemoteWebDriver.FindElement(By by)
TransferPage.get_TransferLink() line 22
SmokeTests.Transferdisplay() line 57

我目前正在尝试单击位于 div 内的 href。无论我尝试什么,似乎都无法点击它。

enter image description here

这是我检查时的元素。

enter image description here

我尝试添加等待 我尝试通过 LinkText、PartialLinkText、cssSelector 和 xPATH 单击

目前我在 TransferPage 类中有这个:

public IWebElement TransferLink => _driver.FindElement(By.CssSelector("#menuLeftRailContainer > div:nth-child(1) > div:nth-child(3)"));

然后在我的实际测试方法中:

_driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
transferPage.TransferLink.Click();

解决方法

您可以尝试以下方法吗

xpath :

//a[@href=''/connect-native/transfer/'']

或 css 选择器

a[href=''/connect-native/transfer/''] 

在代码中:

public IWebElement TransferLink => _driver.FindElement(By.CssSelector("a[href=''/connect-native/transfer/'']"));

因为您在代码中使用的 css 选择器看起来有点乱。你确定有 1/1 匹配的元素吗?

如果这不起作用,您能在您的网页中查找 iframe 吗?

org.openqa.selenium.NoSuchElementException的实例源码

org.openqa.selenium.NoSuchElementException的实例源码

项目:phoenix.webui.framework    文件:CyleSearchStrategy.java   
private WebElement cyleFindElement(List<By> byList)
{
    WebElement webEle = null;

    for (By by : byList)
    {
        try
        {
            webEle = findElement(by);
        }
        catch (NoSuchElementException e)
        {
        }

        if (webEle != null)
        {
            return webEle;
        }
    }

    return null;
}
项目:Selenium-Foundation    文件:Coordinators.java   
/**
 * Returns a 'wait' proxy that determines if an element is either hidden or non-existent.
 *
 * @param locator web element locator
 * @return 'true' if the element is hidden or non-existent; otherwise 'false'
 */
public static Coordinator<Boolean> invisibilityOfElementLocated(final By locator) {
    return new Coordinator<Boolean>() {

        @Override
        public Boolean apply(SearchContext context) {
            try {
                return !(context.findElement(locator).isdisplayed());
            } catch (NoSuchElementException | StaleElementReferenceException e) {
                // NoSuchElementException: The element is not present in DOM.
                // StaleElementReferenceException: Implies that element no longer exists in the DOM.
                return true;
            }
        }

        @Override
        public String toString() {
            return "element to no longer be visible: " + locator;
        }
    };
}
项目:SeWebDriver_Homework    文件:StickersTest.java   
public void CheckStickers() {
    // find number of ducks on main page
    int n = driver.findElements(By.cssSelector("[class=image-wrapper]")).size();
    System.out.println("Number of products available:" + n);
    driver.manage().timeouts().implicitlyWait(50,TimeUnit.SECONDS);
    if (n > 0) {
        products = driver.findElements(By.cssSelector("[class=image-wrapper]"));
        driver.manage().timeouts().implicitlyWait(50,TimeUnit.SECONDS);
        int i = 0;
        while (i < n){
            System.out.print("Duck" + (i+1) + " has a sticker: ");
            //if sticker is available it will be printed,otherwise the message about error will be printed.
         try {
            System.out.println(products.get(i).findElement(By.cssSelector("[class^=sticker]")).getText());
            } catch (NoSuchElementException ex) {
                System.out.println("Error! No sticker found.");
            }
            i++;
        }
    }
}
项目:ats-framework    文件:RealHtmlMultiSelectList.java   
/**
 * select a value
 *
 * @param value the value to select
 */
@Override
@PublicAtsApi
public void setValue(
                      String value ) {

    new RealHtmlElementState(this).waitToBecomeExisting();

    try {
        WebElement element = RealHtmlElementLocator.findElement(this);
        Select select = new Select(element);
        select.selectByVisibleText(value);
    } catch (NoSuchElementException nsee) {
        throw new SeleniumOperationException("Option with label '" + value + "' not found. ("
                                             + this.toString() + ")");
    }
    UiEngineUtilities.sleep();
}
项目:ats-framework    文件:RealHtmlSingleSelectList.java   
/**
 * set the single selection value
 *
 * @param value the value to select
 */
@Override
@PublicAtsApi
public void setValue(
                      String value ) {

    new RealHtmlElementState(this).waitToBecomeExisting();

    try {
        WebElement element = RealHtmlElementLocator.findElement(this);
        Select select = new Select(element);
        select.selectByVisibleText(value);
    } catch (NoSuchElementException nsee) {
        throw new SeleniumOperationException("Option with label '" + value + "' not found. ("
                                             + this.toString() + ")");
    }
    UiEngineUtilities.sleep();
}
项目:selenium-components    文件:SeleniumConditions.java   
@Override
public Boolean get()
{
    return SeleniumUtils.retryOnStale(() -> {
        try
        {
            WebElement element = component.element();

            if (shouldBeVisible)
            {
                return element != null && element.isdisplayed();
            }

            return element == null || !element.isdisplayed();
        }
        catch (NoSuchElementException e)
        {
            return shouldBeVisible ? false : true;
        }

    });
}
项目:selenium-components    文件:SelectableSeleniumComponent.java   
/**
 * Returns true if the component is selected. Waits {@link SeleniumGlobals#getShortTimeoutInSeconds()} seconds for
 * the component to become available.
 *
 * @return true if selected
 */
default boolean isSelected()
{
    try
    {
        return SeleniumUtils.retryOnStale(() -> {
            WebElement element = element();

            return element.isSelected();
        });
    }
    catch (NoSuchElementException e)
    {
        return false;
    }
}
项目:selenium-components    文件:EditableSeleniumComponent.java   
/**
 * Returns true if the component is editable. Waits {@link SeleniumGlobals#getShortTimeoutInSeconds()} seconds for
 * the component to become available.
 *
 * @return true if editable
 */
default boolean isEditable()
{
    try
    {
        return SeleniumUtils.retryOnStale(() -> {
            WebElement element = element();

            return element.isdisplayed() && element.isEnabled();
        });
    }
    catch (NoSuchElementException e)
    {
        return false;
    }
}
项目:selenium-components    文件:EditableSeleniumComponent.java   
/**
 * Returns true if the component is enabled. Waits {@link SeleniumGlobals#getShortTimeoutInSeconds()} seconds for
 * the component to become available.
 *
 * @return true if enabled
 */
default boolean isEnabled()
{
    try
    {
        return SeleniumUtils.retryOnStale(() -> {
            WebElement element = element();

            return element.isEnabled();
        });
    }
    catch (NoSuchElementException e)
    {
        return false;
    }
}
项目:selenium-components    文件:VisibleSeleniumComponent.java   
/**
 * Returns true if a {@link WebElement} described by this component is visible. By default it checks,if the element
 * is visible. This method has no timeout,it does not wait for the component to become existent.
 *
 * @return true if the component is visible
 */
default boolean isVisible()
{
    try
    {
        return SeleniumUtils.retryOnStale(() -> {
            WebElement element = element();

            return element.isdisplayed();
        });
    }
    catch (NoSuchElementException e)
    {
        return false;
    }
}
项目:selenium-components    文件:TagsInputComponent.java   
public void clear()
{
    try
    {
        List<WebElement> removeButtons = searchContext().findElements(By.className("remove-button"));

        for (WebElement removeButton : removeButtons)
        {
            removeButton.click();
        }
    }
    catch (NoSuchElementException e)
    {
        //nothing to do. May be empty
    }
}
项目:devtools-driver    文件:RemoteWebElement.java   
public RemoteWebElement findElementByXpath(String xpath) throws Exception {
  String f =
      "(function(xpath,element) { var result = "
          + JsAtoms.xpath("xpath","element")
          + ";"
          + "return result;})";
  JsonObject response =
      getInspectorResponse(
          f,false,callArgument().withValue(xpath),callArgument().withObjectId(getRemoteObject().getId()));
  RemoteObject ro = inspector.cast(response);
  if (ro == null) {
    throw new NoSuchElementException("cannot find element by Xpath " + xpath);
  } else {
    return ro.getWebElement();
  }
}
项目:mot-automated-testsuite    文件:WebDriverWrapper.java   
/**
 * Enters the specified text into the field,within the specified fieldset.
 * @param text          The text to enter
 * @param fieldLabel    The field label
 * @param fieldsetLabel The fieldset label
 */
public void enterIntoFieldInFieldset(String text,String fieldLabel,String fieldsetLabel) {
    WebElement fieldsetElement;

    try {
        // find the fieldset with the fieldset label
        fieldsetElement = webDriver.findElement(
                By.xpath("//label[contains(text(),'" + fieldsetLabel + "')]/ancestor::fieldset[1]"));

    } catch (NoSuchElementException noSuchElement) {
        fieldsetElement = findFieldsetByLegend(fieldsetLabel);
    }

    // find the specified label (with the for="id" attribute)...
    WebElement labelElement = fieldsetElement.findElement(
            By.xpath(".//label[contains(text(),'" + fieldLabel + "')]"));

    // find the text element with id matching the for attribute
    // (search in the fieldset rather than the whole page,to get around faulty HTML where id's aren't unique!)
    WebElement textElement = fieldsetElement.findElement(By.id(labelElement.getAttribute("for")));
    textElement.clear();
    textElement.sendKeys(text);
}
项目:mot-automated-testsuite    文件:WebDriverWrapper.java   
/**
 * Selects the specified radio button. Supports well-formed labels and radio buttons nested inside the label.
 * @param labelText  The radio button label
 */
public void selecTradio(String labelText) {
    try {
        // find the input associated with the specified (well-formed) label...
        WebElement labelElement = webDriver.findElement(By.xpath("//label[contains(text(),'" + labelText + "')]"));
        webDriver.findElement(By.id(labelElement.getAttribute("for"))).click();

    } catch (NoSuchElementException | IllegalArgumentException ex) {
        webDriver.findElements(By.tagName("label")).stream()
            .filter((l) -> l.getText().contains(labelText)) // label with text
            .map((l) -> l.findElement(By.xpath("./input[@type = 'radio']"))) // nested radio
            .findFirst().orElseThrow(() -> {
                String message = "No radio button found with label (well-formed or nested): " + labelText;
                logger.error(message);
                return new IllegalArgumentException(message);
            }).click();
    }
}
项目:mot-automated-testsuite    文件:WebDriverWrapper.java   
/**
 * Finds the specified checkBox button. Supports well-formed labels and inputs nested inside the label.
 * @param labelText  The checkBox button label
 */
private WebElement findCheckBox(String labelText) {
    try {
        // find the input associated with the specified (well-formed) label...
        WebElement labelElement = webDriver.findElement(By.xpath("//label[contains(text(),'" + labelText + "')]"));
        return webDriver.findElement(By.id(labelElement.getAttribute("for")));

    } catch (NoSuchElementException | IllegalArgumentException ex) {
        return webDriver.findElements(By.tagName("label")).stream()
                .filter((label) -> label.getText().contains(labelText)) // label with text
                .map((label) -> label.findElement(By.xpath("./input[@type = 'checkBox']"))) // nested checkBox
                .findFirst().orElseThrow(() -> {
                    String message = "No checkBox button found with label (well-formed or nested): " + labelText;
                    logger.error(message);
                    return new IllegalArgumentException(message);
                });
    }
}
项目:mot-automated-testsuite    文件:WebDriverWrapper.java   
/**
 * Checks whether a table,identified by having a heading with the specified text,has at least the specified
 * number of rows (ignoring any heading rows).
 * @param headingText       The table heading text to look for
 * @param rows              The minimum number of rows the table must have
 * @return <code>true</code> if the table has at least <code>rows</code> rows.
 */
public boolean checkTableHasRows(String headingText,int rows) {
    try {
        // find the table with a heading containing the specified text...
        WebElement tableElement = webDriver.findElement(
                By.xpath("//th[contains(text(),'" + headingText + "')]//ancestor::table[1]"));

        // then count the number of rows in the table...
        List<WebElement> rowElements = tableElement.findElements(By.tagName("tr"));

        // is the number of rows (minus the heading row) at lest the specified amount?
        return (rowElements.size() - 1) >= rows;

    } catch (NoSuchElementException ex) {
        return false;
    }
}
项目:xtf    文件:DriverUtil.java   
public static void waitFor(WebDriver driver,long timeout,By... elements) throws TimeoutException,InterruptedException {
    try {
        WaitUtil.waitFor(() -> elementsPresent(driver,elements),null,1000L,timeout);
    } catch (TimeoutException ex) {
        try {
            for (By element : elements) {
                WebElement webElement = driver.findElement(element);
                if (!webElement.isdisplayed()) {
                    throw new TimeoutException("Timeout exception during waiting for web element: " + webElement.getText());
                }
            }
        } catch (NoSuchElementException | StaleElementReferenceException x) {
            throw new TimeoutException("Timeout exception during waiting for web element: " + x.getMessage());
        }
    }
}
项目:POM_HYBRID_FRAMEOWRK    文件:WebUtilities.java   
/**
 * Wait for element to appear.
 *
 * @param driver the driver
 * @param element the element
 * @param logger the logger
 */
public static boolean waitForElementToAppear(WebDriver driver,WebElement element,ExtentTest logger) {
    boolean webElementPresence = false;
    try {
        Wait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver).pollingEvery(2,TimeUnit.SECONDS)
                .withTimeout(60,TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
        fluentWait.until(ExpectedConditions.visibilityOf(element));
        if (element.isdisplayed()) {
            webElementPresence= true;
        }
    } catch (TimeoutException toe) {
        logger.log(LogStatus.ERROR,"Timeout waiting for webelement to be present<br></br>" + toe.getStackTrace());
    } catch (Exception e) {
        logger.log(LogStatus.ERROR,"Exception occured<br></br>" + e.getStackTrace());
    }
    return webElementPresence;
}
项目:AutomationFrameworkTPG    文件:BasePage.java   
protected void waitForElements(BasePage page,final WebElement... elements) {
    new webdriverwait(getDriverProxy(),40)
    .withMessage("Timed out navigating to [" + page.getClass().getName() + "]. Expected elements were not found. See screenshot for more details.")
    .until((WebDriver d) -> {
        for (WebElement elm : elements) {
            try {
                elm.isdisplayed();
            } catch (NoSuchElementException e) {
                // This is expected exception since we are waiting for the selenium element to come into existence.
                // This method will be called repeatedly until it reaches timeout or finds all selenium given.
                return false;
            }
        }
        return true;
    });
}
项目:AutomationFrameworkTPG    文件:BasePage.java   
protected void waitForElements(BasePage page,final By... elements) {
    new webdriverwait(getDriverProxy(),40)
    .withMessage("Timed out navigating to [" + page.getClass().getName() + "]. Expected selenium elements were not found. See screenshot for more details.")
    .until((WebDriver d) -> {
        boolean success = true;
        for (By elm : elements) {
            List<WebElement> foundElements = d.findElements(elm);
            if (!foundElements.isEmpty()) {
                try {
                    ((WebElement) foundElements.get(0)).isdisplayed();
                } catch (NoSuchElementException e) {
                    // This is expected exception since we are waiting for the selenium element to come into existence.
                    // This method will be called repeatedly until it reaches timeout or finds all selenium given.
                    success = false;
                    break;
                }
            } else {
                success = false;
                break;
            }
        }
        return success;
    });
}
项目:WebAutomation_AllureParallel    文件:FluentWaiting.java   
public static void waitUntillElementToBeClickable(int TotalTimeInSeconds,int PollingTimeInMilliseconds,WebElement Element)
{
     FluentWait<WebDriver> ClickableWait = new FluentWait<WebDriver>(getWebDriver())
                .withTimeout(TotalTimeInSeconds,TimeUnit.SECONDS)
                .pollingEvery(PollingTimeInMilliseconds,TimeUnit.MILLISECONDS)
                .ignoring(NoSuchElementException.class);

     ClickableWait.until(ExpectedConditions.elementToBeClickable(Element));
}
项目:bobcat    文件:ConfirmationWindow.java   
private void clickButton(final String buttonLabel) {
  final WebElement button =
      bobcatWait.withTimeout(Timeouts.BIG).until(input -> window.findElement(
          By.xpath(String.format(BUTTON_XPATH_FORMATTED,buttonLabel))));

  bobcatWait.withTimeout(Timeouts.MEDIUM).until(ExpectedConditions.elementToBeClickable(button));

  bobcatWait.withTimeout(Timeouts.BIG).until(input -> {
    boolean confirmationWindowClosed;
    try {
      button.click();
      confirmationWindowClosed = !window.isdisplayed();
    } catch (NoSuchElementException | StaleElementReferenceException e) {
      LOG.debug("Confirmation window is not available",e);
      confirmationWindowClosed = true;
    }
    return confirmationWindowClosed;
  });
}
项目:bobcat    文件:AemContextMenu.java   
/**
 * Clicks the selected option in the context menu and waits until context menu disappears.
 *
 * @param option option to click
 * @return this context menu object
 */
public AemContextMenu clickOption(final MenuOption option) {
  bobcatWait.withTimeout(Timeouts.BIG).until(input -> {
    try {
      currentScope.findElement(
          By.xpath(String.format(MENU_OPTION_XPATH,XpathUtils.quote(option.getLabel()))))
          .click();
      currentScope.isdisplayed();
      return Boolean.FALSE;
    } catch (NoSuchElementException e) {
      LOG.debug("MenuOption is not present: ",e);
      return Boolean.TRUE;
    }
  });

  return this;
}
项目:songs_play    文件:eventbriteOAuth2Test.java   
private void signupUser() {
    goToLogin();
    try {
        final String migrationLightBoxSelector = "#migration_lightBox";
        final FluentWebElement migrationLightBox = browser.findFirst(migrationLightBoxSelector);
        migrationLightBox.find(".mfp-close").click();
        browser.await().atMost(5L,TimeUnit.SECONDS).until(migrationLightBoxSelector).areNotdisplayed();
    } catch(final NoSuchElementException nsee) {
        // migration lightBox was not shown,so we do not need to close it
    }

    browser.fill("input",withName("email")).with(eventbrite_USER_EMAIL);
    browser.fill("input",withName("password")).with(System.getenv("eventbrite_USER_PASSWORD"));
    browser.find("input",with("value").equalTo("Log in")).click();
    browser.await().untilPage().isLoaded();

    browser.await().atMost(5,TimeUnit.SECONDS).until("#access_choices_allow").areEnabled();
    browser.find("#access_choices_allow").click();
    browser.await().untilPage().isLoaded();
}
项目:vpMaster    文件:SubMenuPageLoader.java   
private static void generateMarkLinkHashMap(WebDriver webDriver,List<WebElement> markList,Hashtable<String,String> dictMarkLink) {
   for (WebElement element : markList) {
      WebElement hrefLink;
      String markLink = webDriver.getcurrenturl();
      try {
         hrefLink = element.findElement(By.tagName("a"));
         markLink = hrefLink.getAttribute(PageLoaderHelper.HYPER_REFERENCE_ATTRIBUTE_TAG);
      } catch (NoSuchElementException e) {
         //In this case,subMenu has already been selected,the current link is then the mark link
         hrefLink = element.findElement(By.tagName("span"));
      }

      String markNameText = hrefLink.getText().toupperCase();
      dictMarkLink.put(markNameText,markLink);
   }
}
项目:menggeqa    文件:AppiumElementLocator.java   
/**
 * Find the element.
 */
public WebElement findElement() {
    if (cachedElement != null && shouldCache) {
        return cachedElement;
    }
    List<WebElement> result = waitFor();
    if (result.size() == 0) {
        String message = "Can't locate an element by this strategy: " + by.toString();
        if (waitingFunction.foundStaleElementReferenceException != null) {
            throw new NoSuchElementException(message,waitingFunction.foundStaleElementReferenceException);
        }
        throw new NoSuchElementException(message);
    }
    if (shouldCache) {
        cachedElement = result.get(0);
    }
    return result.get(0);
}
项目:PatatiumWebUi    文件:TableElement.java   
/**
 * Get column index from a column name 
 * Or several strings in a cell in first row that can determine a unique column
 * which separated by ","
 * @throws Exception 
 * 
 * @param  String
 * Example: getColumnIndex("ColumnName"),getColumnIndex("namestring1,namestring2")
 * 
 * */
public int getColumnIndex(String columnName){

    String[] columnkey = columnName.split(",");
    StringBuilder sColumnXpath = new StringBuilder(".//tr/th");
    for(int i=0;i<columnkey.length;i++)
    {
        sColumnXpath.append("[contains(.,'").append(columnkey[i]).append("')]");
    }           
    sColumnXpath.append(columnFilter);

    if(table.findElements(By.xpath(".//tr/th")).size()==0)
    {
        throw new NoSuchElementException("column name is not under tag <th>");
    }

    return table.findElement(By.xpath(sColumnXpath.toString())).findElements(By.xpath("./preceding-sibling::th" + columnFilter)).size() + 1;

}
项目:PatatiumWebUi    文件:ElementAction.java   
/**
 * 文本框输入操作
 * @param locator  元素locator
 * @param value 输入值
 */
public void type(Locator locator,String value)
{
    try {
        WebElement webElement=findElement(locator);
        webElement.sendKeys(value);
        log.info("input输入:"+locator.getLocalorName()+"["+"By."+locator.getBy()+":"+locator.getElement()+"value:"+value+"]");
    } catch (NoSuchElementException e) {
        // Todo: handle exception
        log.error("找不到元素,input输入失败:"+locator.getLocalorName()+"["+"By."+locator.getBy()+":"+locator.getElement()+"]");
        e.printstacktrace();
        //throw e;
        //Assertion.flag=false;
    }

}
项目:PatatiumWebUi    文件:ElementAction.java   
/**
 * 选择下拉框操作
 * @param locator  元素locator
 * @param text 选择下拉值
 */
public  void selectByText(Locator locator,String text)
{
    try {
        WebElement webElement=findElement(locator);
        Select select=new Select(webElement);
        log.info("选择select标签:"+locator.getLocalorName()+"["+"By."+locator.getBy()+":"+locator.getElement()+"]");
        try {
            //select.selectByValue(value);
            select.selectByVisibleText(text);
            log.info("选择下拉列表项:" + text);

        } catch (NoSuchElementException notByValue) {
            // Todo: handle exception
            log.info("找不到下拉值,选择下拉列表项失败 " + text);
            throw notByValue;
        }
    } catch (NoSuchElementException e) {
        // Todo: handle exception
        log.error("找不到元素,选择select标签失败:"+locator.getLocalorName()+"["+"By."+locator.getBy()+":"+locator.getElement()+"]");
        throw e;
    }
}
项目:teasy    文件:FindElementsLocator.java   
@Override
public WebElement find() {
    try {
        return driver != null ? driver.findElements(by).get(index) : searchContext.domElements(by).get(index).getWrappedWebElement();
    } catch (indexoutofboundsexception e) {
        throw new NoSuchElementException("Unable to find element with locator " + by + " and index " + index + ",Exception - " + e);
    }
}
项目:teasy    文件:SelectImpl.java   
@Override
public void selectByText(final String text,final String errorMessage) {
    try {
        selectByText(text);
    } catch (NoSuchElementException e) {
        Reporter.log("ERROR: " + errorMessage);
        throw new AssertionError(e);
    }
}
项目:teasy    文件:SelectImpl.java   
@Override
public void selectByIndex(final int index,final String errorMessage) {
    try {
        selectByIndex(index);
    } catch (NoSuchElementException e) {
        Reporter.log("ERROR: " + errorMessage);
        throw new AssertionError(e);
    }
}
项目:teasy    文件:SelectImpl.java   
@Override
public void selectByValue(final String value,final String errorMessage) {
    try {
        selectByValue(value);
    } catch (NoSuchElementException e) {
        Reporter.log("ERROR: " + errorMessage);
        throw new AssertionError(e);
    }
}
项目:Selenium-Foundation    文件:JsUtilityTest.java   
@Test
public void testPropagate() {
    ExamplePage page = getPage();
    try {
        getMetaTagNamed(page.getDriver(),"test");
        fail("No exception was thrown");
    } catch (NoSuchElementException e) {
        assertTrue(e.getMessage().startsWith("No Meta element found with name: "));
    }
}
项目:marathonv5    文件:JTabbedPaneTest.java   
public void invalidTabIndex() throws Throwable {
    driver = new JavaDriver();
    WebElement tab = driver.findElement(By.cssSelector("tabbed-pane::nth-tab(10)"));
    try {
        tab.click();
        throw new MissingException(NoSuchElementException.class);
    } catch (NoSuchElementException e) {
    }
}
项目:marathonv5    文件:JListTest.java   
public void indexOutOfBoundException() throws Throwable {
    driver = new JavaDriver();
    try {
        WebElement findElement = driver.findElement(By.cssSelector("list::nth-item(6)"));
        findElement.click();
        throw new MissingException(NoSuchElementException.class);
    } catch (NoSuchElementException e) {
    }
}
项目:marathonv5    文件:JListXTest.java   
public void listThrowsNSEWhenIndexOutOfBounds() throws Throwable {
    driver = new JavaDriver();
    try {
        WebElement findElement = driver.findElement(By.cssSelector("#list-1::nth-item(31)"));
        findElement.click();
        throw new MissingException(NoSuchElementException.class);
    } catch (NoSuchElementException e) {
    }
}
项目:marathonv5    文件:JavaDriverTest.java   
public void findElementThrowsNoSuchElementIfNotFound() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeto(null);
            frame.setVisible(true);
        }
    });
    try {
        driver.findElement(By.name("click-me-note-there"));
        throw new MissingException(NoSuchElementException.class);
    } catch (NoSuchElementException e) {
    }
}
项目:marathonv5    文件:JTableTest.java   
public void gettableCellNonexistant() throws Throwable {
    driver = new JavaDriver();
    WebElement errCell = driver.findElement(By.cssSelector("table::mnth-cell(20,20)"));
    try {
        errCell.getText();
        throw new MissingException(NoSuchElementException.class);
    } catch (NoSuchElementException e) {
    }
}
项目:marathonv5    文件:JTableTest.java   
public void tableCellEditUneditable() throws Throwable {
    driver = new JavaDriver();
    try {
        WebElement cell = driver.findElement(By.cssSelector("table::mnth-cell(3,1)::editor"));
        cell.sendKeys("Hello World",Keys.ENTER);
        throw new MissingException(NoSuchElementException.class);
    } catch (NoSuchElementException e) {
    }
}

今天关于Selenium-IE 11中的NoSuchWindowExceptionselenium ie options的介绍到此结束,谢谢您的阅读,有关c# – .NET Selenium NoSuchElementException; WebDriverWait.Until()不起作用、java – 在Selenium中避免NoSuchElementException的最好方法是什么?、OpenQA.Selenium.NoSuchElementException:没有这样的元素:无法定位元素 C# 按类查找、org.openqa.selenium.NoSuchElementException的实例源码等更多相关知识的信息可以在本站进行查询。

本文标签: