<legend id='5fcR2'><style id='5fcR2'><dir id='5fcR2'><q id='5fcR2'></q></dir></style></legend>
  • <tfoot id='5fcR2'></tfoot>

      • <bdo id='5fcR2'></bdo><ul id='5fcR2'></ul>

      1. <i id='5fcR2'><tr id='5fcR2'><dt id='5fcR2'><q id='5fcR2'><span id='5fcR2'><b id='5fcR2'><form id='5fcR2'><ins id='5fcR2'></ins><ul id='5fcR2'></ul><sub id='5fcR2'></sub></form><legend id='5fcR2'></legend><bdo id='5fcR2'><pre id='5fcR2'><center id='5fcR2'></center></pre></bdo></b><th id='5fcR2'></th></span></q></dt></tr></i><div id='5fcR2'><tfoot id='5fcR2'></tfoot><dl id='5fcR2'><fieldset id='5fcR2'></fieldset></dl></div>

        <small id='5fcR2'></small><noframes id='5fcR2'>

        selenium chrome 驱动的getText() 方法有时会返回一个空字符串

        getText() method of selenium chrome driver sometimes returns an empty string(selenium chrome 驱动的getText() 方法有时会返回一个空字符串)
        <legend id='1xNPr'><style id='1xNPr'><dir id='1xNPr'><q id='1xNPr'></q></dir></style></legend>

          • <bdo id='1xNPr'></bdo><ul id='1xNPr'></ul>

            <small id='1xNPr'></small><noframes id='1xNPr'>

              <tbody id='1xNPr'></tbody>

                1. <i id='1xNPr'><tr id='1xNPr'><dt id='1xNPr'><q id='1xNPr'><span id='1xNPr'><b id='1xNPr'><form id='1xNPr'><ins id='1xNPr'></ins><ul id='1xNPr'></ul><sub id='1xNPr'></sub></form><legend id='1xNPr'></legend><bdo id='1xNPr'><pre id='1xNPr'><center id='1xNPr'></center></pre></bdo></b><th id='1xNPr'></th></span></q></dt></tr></i><div id='1xNPr'><tfoot id='1xNPr'></tfoot><dl id='1xNPr'><fieldset id='1xNPr'></fieldset></dl></div>

                  <tfoot id='1xNPr'></tfoot>
                2. 本文介绍了selenium chrome 驱动的getText() 方法有时会返回一个空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个奇怪的案例,硒铬驱动程序 getText() 方法 (java) 为某些元素返回一个空字符串,即使它为其他具有相同元素的元素返回一个非空字符串xpath.这是页面的一小部分.

                  I have a curious case where the selenium chrome driver getText() method (java) returns an empty string for some elements, even though it returns a non-empty string for other elements with the same xpath. Here is a bit of the page.

                  <div __gwt_cell="cell-gwt-uid-223" style="outline-style:none;">
                  <div>Text_1</div>
                  <div>Text_2</div>
                  <div>Text_3</div>
                  <div>Text_4</div>
                  <div>Text_5</div>
                  <div>Text_6</div>
                  </div>
                  

                  对于每个内部标签,我可以获得 getTagName()getLocation()isEnabled() 的有效返回值,和 isDisplayed().但是,getText() 会为某些 div 返回一个空字符串.

                  for each of the inner tags, I can get valid return values for getTagName(), getLocation(), isEnabled(), and isDisplayed(). However, getText() returns an empty string for some of the divs.

                  此外,我注意到如果我使用 mac chrome 驱动程序,它始终是 getText() 返回空字符串的Text_5".如果我使用 windows chrome 驱动程序,它始终是 getText() 返回空字符串的Text_2".如果我使用 firefox 驱动程序,getText() 从所有 div 中返回预期的文本.

                  Further, I notice that if I use the mac chrome driver, it is consistently the ‘Text_5’ for which getText() returns an empty string. If I use the windows chrome driver, it is , it is consistently the ‘Text_2’ for which getText() returns an empty string. If I use the firefox driver, getText() returns the expected text from all the divs.

                  有其他人遇到过这种困难吗?

                  Has anyone else had this difficulty?

                  在我的代码中,我使用了类似的东西……

                  In my code, I use something like this…

                  ArrayList<WebElement> list = (ArrayList<WebElement>) driver.findElements(By.xpath("my xPath here"));
                  for (WebElement e: list) System.out.println(e.getText());
                  

                  如下所示,这是我正在使用的实际 xPath.上面的页面片段处理最后两个 div.

                  As suggested below, here is the actual xPath I am using. The page snippet above deals with the last two divs.

                  //*[@class='gwt-DialogBox']//tr[contains(@class,'data-grid-table-row')]//td[contains(@class,'lms-assignment-selection-wizard-cell')]/div/div
                  

                  推荐答案

                  更新: textContent 属性是更好的选择,并且在大多数浏览器中都受支持.这篇博文详细解释了这些差异:innerText vs.文本内容

                  Update: The textContent attribute is a better option and supported across the majority of browsers. The differences are explained in detail at this blog post: innerText vs. textContent

                  作为替代方案,innerText 属性将返回存在于 DOM 中的元素的文本内容.

                  As an alternative, the innerText attribute will return the text content of an element which exists in the DOM.

                  element.getAttribute("innerText")
                  

                  isDisplayed() 方法有时会在元素没有真正隐藏而是在视口之外时绊倒;getText() 为此类元素返回一个空字符串.

                  The isDisplayed() method can sometimes trip over when the element is not really hidden but outside the viewport; getText() returns an empty string for such an element.

                  您也可以通过使用 javascript 滚动到它来将元素带入视口,如下所示:

                  You can also bring the element into the viewport by scrolling to it using javascript, as follows:

                  ((JavaScriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", element);
                  

                  然后 getText() 应该返回正确的值.

                  and then getText() should return the correct value.

                  isDisplayed() 方法的详细信息可以在这个 SO 问题中找到:

                  Details on the isDisplayed() method can be found in this SO question:

                  Selenium WebDriver 的 isDisplayed() 方法是如何工作的

                  这篇关于selenium chrome 驱动的getText() 方法有时会返回一个空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Lucene Porter Stemmer not public(Lucene Porter Stemmer 未公开)
                  How to index pdf, ppt, xl files in lucene (java based or python or php any of these is fine)?(如何在 lucene 中索引 pdf、ppt、xl 文件(基于 java 或 python 或 php 中的任何一个都可以)?)
                  KeywordAnalyzer and LowerCaseFilter/LowerCaseTokenizer(KeywordAnalyzer 和 LowerCaseFilter/LowerCaseTokenizer)
                  How to search between dates (Hibernate Search)?(如何在日期之间搜索(休眠搜索)?)
                  How to get positions from a document term vector in Lucene?(如何从 Lucene 中的文档术语向量中获取位置?)
                  Java Lucene 4.5 how to search by case insensitive(Java Lucene 4.5如何按不区分大小写进行搜索)

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

                        <tfoot id='oUe3g'></tfoot>

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