久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <small id='mV290'></small><noframes id='mV290'>

    <tfoot id='mV290'></tfoot>
      <bdo id='mV290'></bdo><ul id='mV290'></ul>
    <legend id='mV290'><style id='mV290'><dir id='mV290'><q id='mV290'></q></dir></style></legend>

      <i id='mV290'><tr id='mV290'><dt id='mV290'><q id='mV290'><span id='mV290'><b id='mV290'><form id='mV290'><ins id='mV290'></ins><ul id='mV290'></ul><sub id='mV290'></sub></form><legend id='mV290'></legend><bdo id='mV290'><pre id='mV290'><center id='mV290'></center></pre></bdo></b><th id='mV290'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='mV290'><tfoot id='mV290'></tfoot><dl id='mV290'><fieldset id='mV290'></fieldset></dl></div>
      1. WebDriver 不能可靠地單擊鏈接或按鈕

        WebDriver does not reliably click links or buttons(WebDriver 不能可靠地單擊鏈接或按鈕)

          <tbody id='B65ft'></tbody>

        <i id='B65ft'><tr id='B65ft'><dt id='B65ft'><q id='B65ft'><span id='B65ft'><b id='B65ft'><form id='B65ft'><ins id='B65ft'></ins><ul id='B65ft'></ul><sub id='B65ft'></sub></form><legend id='B65ft'></legend><bdo id='B65ft'><pre id='B65ft'><center id='B65ft'></center></pre></bdo></b><th id='B65ft'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='B65ft'><tfoot id='B65ft'></tfoot><dl id='B65ft'><fieldset id='B65ft'></fieldset></dl></div>
          1. <legend id='B65ft'><style id='B65ft'><dir id='B65ft'><q id='B65ft'></q></dir></style></legend>

                <tfoot id='B65ft'></tfoot>

                <small id='B65ft'></small><noframes id='B65ft'>

                • <bdo id='B65ft'></bdo><ul id='B65ft'></ul>
                • 本文介紹了WebDriver 不能可靠地單擊鏈接或按鈕的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我一直在拼命想讓 WebDriver 可靠地單擊按鈕或鏈接,但它就是不想合作.我嘗試了不同的方法,從設(shè)置隱式超時(shí)到下面的代碼,假設(shè)單擊并等待元素出現(xiàn).

                  I have been desperately trying to get WebDriver to click a button or link reliably, but it just does not want to cooperate. I have tried different methods from setting an implicit timeout, to the below code which is suppose to click and wait for the element to appear.

                  下面的代碼片段是在互聯(lián)網(wǎng)上的某個(gè)地方找到的,它是我最接近可靠地獲得一個(gè)按鈕或鏈接來點(diǎn)擊的地方.除了它在調(diào)試模式下的工作方式與我在夜間回歸測(cè)試期間執(zhí)行時(shí)的工作方式不同.

                  The below snippet of code was found somewhere on the internet, and it the closest I have come to reliably getting a button or link to click. Except it does not work the same in debug mode as it does when executed during my nightly regression testing.

                  有誰知道在瀏覽器中單擊按鈕或鏈接的另一種方法?或者我應(yīng)該使用 Selenium 1 而不是 WebDriver,因?yàn)樗露鵁o法可靠使用.

                  Does anyone know of another method to click a button or link in a browser? Or should I be using Selenium 1 and not WebDriver as it is too new to be used reliably.

                  public void waitAndClick(WebDriver driver, By by) {
                      WebDriverWait wait = new WebDriverWait(driver, 10000, 2000);
                      Function<WebDriver, Boolean> waitForElement = new waitForElement(by);
                      wait.until(waitForElement);
                  
                      Actions builder = new Actions(driver);
                      builder.click(driver.findElement(by))
                              .perform();
                  }
                  
                  private class waitForElement implements Function<WebDriver, Boolean> {
                      private final By by;
                  
                      private String text = null;
                  
                      public waitForElement(By by) {
                          this.by = by;
                      }
                  
                      public waitForElement(By by, String text) {
                          this.by = by;
                          this.text = text;
                      }
                  
                      @Override
                      public Boolean apply(WebDriver from) {
                          if (this.text != null) {
                              for (WebElement e : from.findElements(this.by)) {
                                  if (e.getText().equals(this.text)) {
                                      return Boolean.TRUE;
                                  }
                              }
                  
                              return Boolean.FALSE;
                          } else {
                              try {
                                  driver.switchTo().defaultContent().switchTo().frame("top");
                                  from.findElement(this.by);
                              } catch (Exception e) {
                                  logger.error("Unable to find "" + this.by.toString() + "". Retrying....");
                                  return Boolean.FALSE;
                              }
                              logger.info("Found "" + this.by.toString() + "".");
                              return Boolean.TRUE;
                          }
                      }
                  }
                  

                  在 Eclipse 調(diào)試模式下控制臺(tái)輸出:

                  Console out in Eclipse Debug mode:

                  16:07:08,109 INFO  WebDriverUtility: apply Found "By.linkText: Classes".
                  16:07:10,514 INFO  WebDriverUtility: apply Found "By.linkText: Reports".
                  16:07:17,028 ERROR WebDriverUtility: apply Unable to find "By.linkText: Users". Retrying....
                  16:07:26,369 INFO  WebDriverUtility: apply Found "By.linkText: Users".
                  16:07:38,272 ERROR WebDriverUtility: apply Unable to find "By.linkText: System". Retrying....
                  16:07:41,334 INFO  WebDriverUtility: apply Found "By.linkText: System".
                  16:07:47,722 ERROR WebDriverUtility: apply Unable to find "By.linkText: Schools". Retrying....
                  16:07:50,565 INFO  WebDriverUtility: apply Found "By.linkText: Schools".
                  

                  從 Eclipse 運(yùn)行時(shí)控制臺(tái)退出:

                  Console out when running from Eclipse:

                  16:14:04,179 INFO  WebDriverUtility: apply Found "By.linkText: Classes".
                  16:14:04,726 INFO  WebDriverUtility: apply Found "By.linkText: Reports".
                  16:14:09,771 INFO  PageAPITesting: login org.openqa.selenium.NoSuchElementException: Unable to find element with link text == Reports (WARNING: The server did not provide any stacktrace information)
                  For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
                  Build info: version: '2.0rc3', revision: '12536', time: '2011-06-20 18:19:52'
                  System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_24'
                  Driver info: driver.version: RemoteWebDriver
                  16:14:09,865 INFO  PageAPITesting: login current tabs is Classes
                  16:14:09,958 INFO  WebDriverUtility: apply Found "By.linkText: Schools".
                  16:14:10,240 INFO  PageAPITesting: login java.lang.IllegalStateException: Unable to navigate to the ca.schoolspecialty.qa.api.pages.schools.MenuSchoolPage page
                  

                  推薦答案

                  我沒有看到任何奇怪的行為,

                  I don't see any strange behavior,

                  wait.until 方法,它的作用是在函數(shù)上調(diào)用apply 方法,直到它返回一些東西或者有一個(gè)Time Out.

                  The wait.until method, what it does is to call the apply method on the function until it returns something or there is a Time Out.

                  如果元素尚未創(chuàng)建,則有時(shí)會(huì)收到 NotFoundExceptions,實(shí)際上,如果您查看代碼,您會(huì)看到:

                  It's expected to receive NotFoundExceptions sometimes if the element hasn't been created yet, actually if you look in the code you'll see this:

                   while (clock.isNowBefore(end)) {
                    try {
                      T value = isTrue.apply(driver);
                  
                      if (value != null && Boolean.class.equals(value.getClass())) {
                        if (Boolean.TRUE.equals(value)) {
                          return value;
                        }
                      } else if (value != null) {
                        return value;
                      }
                    } catch (NotFoundException e) {
                      // Common case in many conditions, so swallow here, but be ready to
                      // rethrow if it the element never appears.
                      lastException = e;
                    }
                    sleep();
                  

                  它捕獲異常并且什么都不做,問題是您覆蓋了應(yīng)用程序以捕獲并記錄該異常,所以您看到的是預(yù)期的行為,沒有其他方法可以檢查元素是否已創(chuàng)建不斷地要求它.

                  It catches the exception and does nothing with it, the problem is that you overwrote the apply to catch and logs that exception, so what you are seeing is the expected behavior, there's no other way to check if the element has been created that continuously asking for it.

                  我自己正在將這段代碼用于函數(shù)生成器:

                  I myself I'm using this code for the Function generator:

                  public static Function<WebDriver, WebElement> presenceOfElementLocated(
                          final By locator) {
                      return new Function<WebDriver, WebElement>() {
                          @Override
                          public WebElement apply(WebDriver driver) {
                              return driver.findElement(locator);
                          }
                      };
                  }
                  

                  更簡(jiǎn)單,您可以用于任何定位器

                  Is a lot simpler and you can use for any Locator

                  這篇關(guān)于WebDriver 不能可靠地單擊鏈接或按鈕的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測(cè) 32 位 int 上的整數(shù)溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關(guān)系嗎?)
                  How to convert Integer to int?(如何將整數(shù)轉(zhuǎn)換為整數(shù)?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內(nèi)創(chuàng)建一個(gè)隨機(jī)打亂數(shù)字的 int 數(shù)組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠?qū)?0xff000000 存儲(chǔ)為 int?)
                  <tfoot id='enmbV'></tfoot>
                  • <bdo id='enmbV'></bdo><ul id='enmbV'></ul>

                    <i id='enmbV'><tr id='enmbV'><dt id='enmbV'><q id='enmbV'><span id='enmbV'><b id='enmbV'><form id='enmbV'><ins id='enmbV'></ins><ul id='enmbV'></ul><sub id='enmbV'></sub></form><legend id='enmbV'></legend><bdo id='enmbV'><pre id='enmbV'><center id='enmbV'></center></pre></bdo></b><th id='enmbV'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='enmbV'><tfoot id='enmbV'></tfoot><dl id='enmbV'><fieldset id='enmbV'></fieldset></dl></div>

                        <tbody id='enmbV'></tbody>

                        <legend id='enmbV'><style id='enmbV'><dir id='enmbV'><q id='enmbV'></q></dir></style></legend>

                            <small id='enmbV'></small><noframes id='enmbV'>

                          1. 主站蜘蛛池模板: 成人精品一区 | 午夜专区| 久久免费观看视频 | 久久伊人精品 | 综合久久综合久久 | 成人在线免费观看视频 | 在线视频 亚洲 | 一区二区三区欧美 | 日本三级电影在线免费观看 | av喷水 | 欧美国产日韩一区 | 久久网一区二区 | 中文字幕免费视频 | 999国产精品视频免费 | 国产在线观看免费 | 亚洲最新在线视频 | 日韩欧美一区二区三区免费观看 | 国产精品久久久久久婷婷天堂 | 盗摄精品av一区二区三区 | 在线视频第一页 | 国产精品久久久久久久久久久免费看 | 日韩在线91 | 日韩人体视频 | 国产色网 | 亚洲欧美国产精品久久 | 欧美乱码精品一区二区三区 | 欧美一级特黄aaa大片在线观看 | www.久久久.com | 一区中文字幕 | 欧美成人精品激情在线观看 | 国产美女在线观看 | 麻豆久久久久 | 黄色成人免费看 | 久久国产精品免费视频 | 国产欧美在线一区 | 国产一区 | 国产成人免费视频 | 国产精品18久久久 | 国产激情精品视频 | 国产日韩欧美一区二区在线播放 | 免费在线观看av网址 |