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

      1. <tfoot id='Kasfr'></tfoot>

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

        • <bdo id='Kasfr'></bdo><ul id='Kasfr'></ul>
        <legend id='Kasfr'><style id='Kasfr'><dir id='Kasfr'><q id='Kasfr'></q></dir></style></legend>

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

      2. 在 Selenium 中為每個(gè)元素使用多個(gè)定位器的優(yōu)缺點(diǎn)

        Pros/cons for using multiple locators per element in Selenium?(在 Selenium 中為每個(gè)元素使用多個(gè)定位器的優(yōu)缺點(diǎn)?)
        <legend id='dwj3v'><style id='dwj3v'><dir id='dwj3v'><q id='dwj3v'></q></dir></style></legend>
      3. <small id='dwj3v'></small><noframes id='dwj3v'>

          <bdo id='dwj3v'></bdo><ul id='dwj3v'></ul>
            <tbody id='dwj3v'></tbody>

                  <tfoot id='dwj3v'></tfoot>
                  <i id='dwj3v'><tr id='dwj3v'><dt id='dwj3v'><q id='dwj3v'><span id='dwj3v'><b id='dwj3v'><form id='dwj3v'><ins id='dwj3v'></ins><ul id='dwj3v'></ul><sub id='dwj3v'></sub></form><legend id='dwj3v'></legend><bdo id='dwj3v'><pre id='dwj3v'><center id='dwj3v'></center></pre></bdo></b><th id='dwj3v'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='dwj3v'><tfoot id='dwj3v'></tfoot><dl id='dwj3v'><fieldset id='dwj3v'></fieldset></dl></div>
                  本文介紹了在 Selenium 中為每個(gè)元素使用多個(gè)定位器的優(yōu)缺點(diǎn)?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我正在測試一個(gè)仍在開發(fā)中的網(wǎng)站.

                  I am testing a website which is still in development.

                  通常一個(gè)元素的 id、類、文本或在 DOM 中的位置會(huì)改變.然后我一直使用的定位器將無法找到該元素.

                  Often an element's id, class, text, or position in the DOM will change. And then the locator I've been using will no longer be able to find the element.

                  但這些功能仍然正常運(yùn)行.當(dāng)沒有實(shí)際回歸時(shí),我不希望多個(gè)測試失敗.

                  But the features are still functioning properly. I don't want several tests to fail when there is no actual regression.

                  因此,我沒有為每個(gè)元素使用一個(gè)定位器,而是有一個(gè)定位器集合.

                  So instead of having a single locator for each element, I have a collection of locators.

                  public static final ArrayList<By> LOGIN_ANCHOR_LOCATORS = new ArrayList<By>();
                  
                  static {
                       LOGIN_ANCHOR_LOCATORS.add(By.id("loginLink"));
                       LOGIN_ANCHOR_LOCATORS.add(By.linkText("Login"));
                       LOGIN_ANCHOR_LOCATORS.add(By.xpath("/html/body/div[5]/a"));         
                  }
                  

                  我查找元素的方法如下:

                  My method for finding the element looks like this:

                  public WebElement locateElement(ArrayList<By> locators){
                  
                      // create an element to return
                      WebElement element = null;
                  
                      // until the desired element is found...
                      while (element == null){
                  
                          // loop through the locators
                          for (By locator : locators){
                  
                              // try to find by locator
                              element = customWait.until(ExpectedConditions.presenceOfElementLocated(locator));
                  
                              // if not found...
                              if (element == null){
                  
                                  // log the failure
                                  logFailingLocator(locator);
                              }
                          }
                      }
                      return element;
                  }
                  

                  它試圖找到集合中第一個(gè)定位器的元素,只有當(dāng)它失敗時(shí),才嘗試下一個(gè)定位器.

                  It tries to find the element with the first locator in the collection, and only if it fails, try the next locator.

                  集合是一個(gè) ArrayList (順序由插入順序定義),這意味著我的 for 循環(huán) 將按照它們添加到列表中的順序嘗試每個(gè)定位器.

                  The collection is an ArrayList (order is defined by insertion order), which means my for loop will try each locator in the order which they were added to the List.

                  我通過按特定順序添加定位器來初始化上面的列表.id 是第一位的,因?yàn)槲艺J(rèn)為如果元素在 DOM 中的位置發(fā)生變化,但它保留了它的 id,那么這將是我最有可能找到正確元素的方式.Xpath 是最后一個(gè),因?yàn)榧词?id/class/text 發(fā)生了變化,但在 DOM 中該位置仍然存在相同類型的元素,它可能是正確的元素,但可能不如其他定位器那么確定.

                  I initialized the list above by adding the locators in a particular order. Id is first, because I figure if the element's position in the DOM changes, but it retains its id, then that will be the way I'll be most likely to locate the correct element. Xpath is last because even if the id/class/text changes, but there is still the same type of element in the DOM at that position, it's probably the right element, but maybe less certain than other locators would be.

                  我正在使用忽略 NoSuchElementException 的流暢等待:

                  I'm using a fluent wait which ignores NoSuchElementException:

                  // Wait 5 seconds for an element to be present on the page, checking
                  // for its presence once every quarter of a second.
                  Wait<WebDriver> customWait = new FluentWait<WebDriver>(driver)
                          .withTimeout(5L, TimeUnit.SECONDS)
                          .pollingEvery(250L, TimeUnit.MILLISECONDS)
                          .ignoring(NoSuchElementException.class);
                  

                  因此,當(dāng)一個(gè)定位器失敗時(shí),它不會(huì)中斷循環(huán) - 它只是記錄失敗,然后繼續(xù)嘗試下一個(gè)定位器.

                  So when one locator fails, it won't break the loop - it just logs the failure and then still goes on to try the next locator.

                  如果所有定位器都失敗了,那么元素將保持為空,測試將失敗,原因很可能是特性/功能的實(shí)際回歸.

                  If all the locators fail, then the element will remain null, the test will fail, and it's far more likely the reason is actual regression of features/functionality.

                  我會(huì)定期檢查我的日志中是否存在具有 1 或 2 個(gè)失敗定位器的任何元素,同時(shí)在我的 pageObject 中更新它們,同時(shí)測試?yán)^續(xù)順利運(yùn)行.

                  I periodically check my logs for any element with 1 or 2 failing locators, and update them in my pageObject in the meantime, while tests continue running smoothly.

                  以這種方式設(shè)置我的項(xiàng)目有什么優(yōu)點(diǎn)或缺點(diǎn)?

                  What are pros or cons to setting up my project this way?

                  推薦答案

                  這是一種有趣的方法,但我擔(dān)心您可能會(huì)掩蓋其他問題.我更愿意與開發(fā)人員更密切地合作,以避免一開始就破壞 UI 問題.

                  It's an interesting approach, but I'm concerned you might be masking other issues. I'd prefer to work more closely with the developers to avoid breaking UI issues in the first place.

                  不斷變化的 ID 是動(dòng)態(tài)生成的嗎?如果是這種情況,請(qǐng)查看是否無法在 ID 上獲得后綴,例如 _loginlink.您可能還必須使用從附近的靜態(tài) ID 開始的 XPath://div[@id='login_link_container'/a".(從文檔的根目錄開始,如您的示例所示,這是一個(gè)痛苦的秘訣!:))

                  Are the changing IDs dynamically produced? If that's the case, look to see if you can't get a suffix on the IDs, something like _loginlink. You might also have to work with an XPath that starts from a nearby static ID: "http://div[@id='login_link_container'/a". (Starting from the root of the document like your example shows is a recipe for pain! :) )

                  這篇關(guān)于在 Selenium 中為每個(gè)元素使用多個(gè)定位器的優(yōu)缺點(diǎn)?的文章就介紹到這了,希望我們推薦的答案對(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?(如何檢測 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?)

                      <tbody id='vfSdL'></tbody>

                    • <small id='vfSdL'></small><noframes id='vfSdL'>

                        <tfoot id='vfSdL'></tfoot>
                      • <legend id='vfSdL'><style id='vfSdL'><dir id='vfSdL'><q id='vfSdL'></q></dir></style></legend>
                          <i id='vfSdL'><tr id='vfSdL'><dt id='vfSdL'><q id='vfSdL'><span id='vfSdL'><b id='vfSdL'><form id='vfSdL'><ins id='vfSdL'></ins><ul id='vfSdL'></ul><sub id='vfSdL'></sub></form><legend id='vfSdL'></legend><bdo id='vfSdL'><pre id='vfSdL'><center id='vfSdL'></center></pre></bdo></b><th id='vfSdL'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vfSdL'><tfoot id='vfSdL'></tfoot><dl id='vfSdL'><fieldset id='vfSdL'></fieldset></dl></div>
                          • <bdo id='vfSdL'></bdo><ul id='vfSdL'></ul>
                          • 主站蜘蛛池模板: 深夜爽视频 | jizz在线看片| aaaa日韩| 国产一区久久精品 | 久久另类 | 日本91av视频 | 99小视频| 国产一区二区在线免费播放 | 日韩成人在线一区 | 欧美人成在线视频 | 亚洲一区二区三区在线 | 精品国产乱码久久久久久闺蜜 | 日韩和的一区二区 | 亚洲欧美日韩精品 | 伊人一区| 亚洲狠狠丁香婷婷综合久久久 | 亚洲综合一区二区三区 | 久久久久久久一区 | 精品九九久久 | 久久精品国产一区二区三区不卡 | 喷潮网站 | 欧美在线国产精品 | 99久久精品国产麻豆演员表 | 久久久久国产精品午夜一区 | 国产精品亚洲第一区在线暖暖韩国 | 亚洲精品国产电影 | 日韩三区 | 国产一级片免费视频 | 天天草夜夜骑 | 国产精品a久久久久 | 日韩在线资源 | 亚洲电影一区二区三区 | 在线成人精品视频 | 神马久久久久久久久久 | 中文字幕电影在线观看 | 国产日产精品一区二区三区四区 | 国产激情综合五月久久 | 亚洲传媒在线 | 色综合久久天天综合网 | 黄视频免费| 福利影院在线看 |