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

<tfoot id='lIG1n'></tfoot>

    • <bdo id='lIG1n'></bdo><ul id='lIG1n'></ul>

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

      Selenium ChromeDriver:增加獲取 WebElement 文本的時間

      Selenium ChromeDriver: increasing time of getting WebElement Text(Selenium ChromeDriver:增加獲取 WebElement 文本的時間)

      <i id='4KkkT'><tr id='4KkkT'><dt id='4KkkT'><q id='4KkkT'><span id='4KkkT'><b id='4KkkT'><form id='4KkkT'><ins id='4KkkT'></ins><ul id='4KkkT'></ul><sub id='4KkkT'></sub></form><legend id='4KkkT'></legend><bdo id='4KkkT'><pre id='4KkkT'><center id='4KkkT'></center></pre></bdo></b><th id='4KkkT'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='4KkkT'><tfoot id='4KkkT'></tfoot><dl id='4KkkT'><fieldset id='4KkkT'></fieldset></dl></div>
        <tbody id='4KkkT'></tbody>
      1. <small id='4KkkT'></small><noframes id='4KkkT'>

      2. <tfoot id='4KkkT'></tfoot>
            <bdo id='4KkkT'></bdo><ul id='4KkkT'></ul>

              <legend id='4KkkT'><style id='4KkkT'><dir id='4KkkT'><q id='4KkkT'></q></dir></style></legend>
              1. 本文介紹了Selenium ChromeDriver:增加獲取 WebElement 文本的時間的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我有一個代碼可以遍歷表的行和列,我想將它的值添加到列表中.

                I have a code in which I traverse table rows and columns, and I'd like to add it's values to a list.

                這需要我大量的時間.

                所以我添加了一個時間測量,我注意到由于某種原因,時間逐行增加.

                So I added a time measurement, and I noticed that for some reason the time increases from row to row.

                我不明白為什么.

                你能建議嗎?

                private void buildTableDataMap() {
                
                    WebElement table = chromeWebDriver.findElement(By.id("table-type-1"));
                
                    List<WebElement> rows = table.findElements(By.tagName("tr"));
                
                    theMap.getInstance().clear();
                
                    String item;
                    for (WebElement row : rows) {
                
                        ArrayList<String> values = new ArrayList<>(); 
                
                        List<WebElement> tds = row.findElements(By.tagName("td"));
                
                        if(tds.size() > 0){
                
                            WebElement last = tds.get(tds.size() - 1);
                
                            long time = System.currentTimeMillis();
                
                            values.addAll(tds.stream().map(e->e.getText()).collect(Collectors.toList()));
                
                            System.out.println(System.currentTimeMillis() - time);
                
                            //remove redundant last entry:
                            values.remove(tds.size() - 1);
                            callSomeFunc(values, last);
                
                            item = tds.get(TABLE_COLUMNS.NAME_COL.getNumVal()).getText();
                            item = item.replaceAll("[^.\- /'&A-Za-z0-9]", "").trim();//remove redundant chars
                
                            theMap.getInstance().getMap().put(item, values);
                        }
                    }
                }
                

                <小時>

                伙計們,我繼續研究.首先,弗洛倫特的友好回答對我沒有幫助,因為至少據我了解,它返回了我必須解析的字符串數組列表,我不太喜歡這種解決方案......


                Guys, I continued researching. First of all, Florent's kind answer did not help me because, at lease as I understand, It returned me an array list of strings which I had to parse, and I don't like this kind of solution too much...

                所以我發現 e.getText() 調用在每次調用之間的時間都在增加,從而解決了這個問題!!!我也嘗試了 e.getAttribute("innerText") 但沒有改變.無法理解為什么.有什么想法可以解決嗎?

                So I nailed the problem in finding that the e.getText() call was increasing in time from call to call!!! I also tried e.getAttribute("innerText") instead but no change. Can't understand why. Any idea to solve?

                            WebElement last = null;
                            for (WebElement e : tds){
                                last = e;
                
                                long tm1 = 0, tm2 = 0;
                                if(Settings.verboseYN) {
                                    tm1 = System.currentTimeMillis();
                                }
                                s = e.getText(); //This action increases in time!!!
                                if(Settings.verboseYN) {
                                    tm2 = System.currentTimeMillis();
                                }
                                values.add(s); //a 0 ms action!!!
                                if(Settings.verboseYN) {
                                    System.out.println("e.getText()) took " + (tm2 - tm1) + " ms...");
                                }
                            }
                

                這是 getText 所用時間的圖表...

                That is an graph of the time getText took...

                18 年 5 月 8 日增加執行時間的另一個來源是:

                08-May-18 Another source of growing execution time is this one:

                void func(WebElement anchorsElement){
                
                    List<WebElement> anchors = anchorsElement.findElements(By.tagName("a"));
                
                    for (WebElement a : anchors) {
                
                        if (a.getAttribute("class").indexOf("a") > 0)
                            values.add("A");
                        else if (a.getAttribute("class").indexOf("b") > 0)
                            values.add("B");
                        else if (a.getAttribute("class").indexOf("c") > 0)
                            values.add("C");
                
                    }
                }
                

                每個函數只有 5 次迭代,但每次調用該函數仍會增加其執行時間.這個也有解決辦法嗎?

                Every functions has 5 iterations only, but still each call to the function increases its execution time. Is there a solution for this one as well?

                推薦答案

                您面臨的問題是因為 Selenium 的設計方式.讓我們看看 JavaScript get 是如何執行的或操作是如何執行的

                The problem you are facing is because of the way Selenium works by design. Let's look at how a JavaScript get's executed or a operation is performed

                tds.get(TABLE_COLUMNS.NAME_COL.getNumVal()).getText();
                

                你有一個對象的集合.selenium 驅動程序在瀏覽器端為每個對象分配一個唯一 ID

                You have a collection of objects. Each object is assigned a unique ID on the browser side by the selenium driver

                所以當你執行 getText() 時會發生以下情況

                So when you do a getText() below is what happens

                Your code -> HTTP Request -> Browser Driver -> Browser ->
                                                                        |
                           <---------------------------------------------
                

                現在,如果您有一個 400rx10c 的表,那么它會占用 4000 個 HTTP 調用,即使一個調用需要 10 毫秒,我們正在查看一個 40000ms~=40sec,這是讀取表格的一個不錯的延遲

                Now if you have a table of 400rx10c then it accounts to 4000 HTTP calls, even if one call takes 10ms, we are looking at a 40000ms~=40sec, which is a decent delay to read a table

                所以你想要做的是通過執行一個返回二維數組的 javascript 來一次性獲取所有數據.這很簡單,我在下面的網站上找到了一個代碼

                So what you want to do is to get all the data in single go by executing a javascript which give you 2d array back. It is quite simple, I found a code on below site

                http://cwestblog.com/2016/08/21/javascript-snippet-convert-html-table-to-2d-array/

                function tableToArray(tbl, opt_cellValueGetter) {
                  opt_cellValueGetter = opt_cellValueGetter || function(td) { return td.textContent || td.innerText; };
                  var twoD = [];
                  for (var rowCount = tbl.rows.length, rowIndex = 0; rowIndex < rowCount; rowIndex++) {
                    twoD.push([]);
                  }
                  for (var rowIndex = 0, tr; rowIndex < rowCount; rowIndex++) {
                    var tr = tbl.rows[rowIndex];
                    for (var colIndex = 0, colCount = tr.cells.length, offset = 0; colIndex < colCount; colIndex++) {
                      var td = tr.cells[colIndex], text = opt_cellValueGetter(td, colIndex, rowIndex, tbl);
                      while (twoD[rowIndex].hasOwnProperty(colIndex + offset)) {
                        offset++;
                      }
                      for (var i = 0, colSpan = parseInt(td.colSpan, 10) || 1; i < colSpan; i++) {
                        for (var j = 0, rowSpan = parseInt(td.rowSpan, 10) || 1; j < rowSpan; j++) {
                          twoD[rowIndex + j][colIndex + offset + i] = text;
                        }
                      }
                    }
                  }
                  return twoD;
                }
                

                我假設您將上述腳本存儲在 SCRIPT 變量中,然后您可以像下面這樣運行它

                I assume you store the above script in a SCRIPT variable and then you can run it like below

                WebDriver driver = ((RemoteWebElement)table).getWrappedDriver();
                Object result = ((JavascriptExecutor)driver).executeScript(SCRIPT + "
                 return tableToArray(arguments[0]);" , table);
                

                這將為您提供一個二維數據數組,然后您可以按照自己喜歡的方式處理它

                This will get you a 2D array of the data and you can then process it the way you like it

                這篇關于Selenium ChromeDriver:增加獲取 WebElement 文本的時間的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                相關文檔推薦

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

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

                        <i id='rAgdD'><tr id='rAgdD'><dt id='rAgdD'><q id='rAgdD'><span id='rAgdD'><b id='rAgdD'><form id='rAgdD'><ins id='rAgdD'></ins><ul id='rAgdD'></ul><sub id='rAgdD'></sub></form><legend id='rAgdD'></legend><bdo id='rAgdD'><pre id='rAgdD'><center id='rAgdD'></center></pre></bdo></b><th id='rAgdD'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='rAgdD'><tfoot id='rAgdD'></tfoot><dl id='rAgdD'><fieldset id='rAgdD'></fieldset></dl></div>
                          主站蜘蛛池模板: 亚洲三区在线观看 | 91久操网 | 亚洲欧美日韩精品久久亚洲区 | 国产精品久久久久久久久婷婷 | 日韩欧美一区在线 | 自拍偷拍精品 | 欧美精品啪啪 | 亚洲欧洲一区二区 | 亚洲精品小视频在线观看 | 国产欧美精品一区二区色综合 | 99久久精品一区二区成人 | 人人鲁人人莫人人爱精品 | 亚州毛片 | 激情福利视频 | 亚洲 中文 欧美 日韩 在线观看 | 欧美日韩国产一区二区三区 | 久草精品视频 | 日韩高清中文字幕 | 久久九精品 | 狠狠夜夜| 午夜午夜精品一区二区三区文 | 伊人网一区 | 男女网站免费观看 | 亚洲一区二区三区福利 | 国产成人精品一区二区三区网站观看 | 亚洲成人免费视频 | 久久国产欧美日韩精品 | 欧美理论片在线观看 | 亚洲精品电影网在线观看 | 99久久电影 | 欧美精品一区二区三区在线播放 | 人人干人人看 | 亚洲午夜精品一区二区三区他趣 | 欧美日韩在线视频一区 | 精品国产欧美一区二区三区成人 | 成人av免费看 | 在线观看免费av网 | 国产精品一区在线 | 亚洲综合国产精品 | 国产999精品久久久 精品三级在线观看 | 欧美精品一区二区三区在线播放 |