- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我很难检索元素的文本,由于某种原因,WebDriver 可以找到该元素,但无法检索文本,我怀疑是因为由于某种原因该元素对 WebDriver 不可见,我稍后会讲到这一点。
这是 HTML 片段:
<td id="x-auto-4169" class="x-grid3-col x-grid3-cell x-grid3-td-badCalls " style="width:53px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-badCalls" unselectable="on">0</div>
</td>
到达此位置的 Xpath 是
String valueXpath = "((//div[@id=\"QosDashpardPanelBottom\"]//div[@id=\"CollectorQoSPerformanceMetricsgrid\"]//div[contains(@class, \"x-grid3-row x-unselectable-single\")])[" + j + "]//div)[" + i + "]";
WebElement value = driver.findElement(By.xpath(valueXpath));
其中“j”是表/网格中的行号,“i”是列号。我知道 Selenium 可以找到该元素,因为我可以做到
WebElement class = driver.findElement(By.xpath(fullXpath));
String classAttr = arg.getAttribute("class");
我回来了
x-grid3-cell-inner x-grid3-col-badCalls
但是当我尝试
String cellValue = value.getText();
System.out.println(cellValue);
我得到一个空字符串。我盯着我的电脑屏幕,我可以看到该值,它是可见的,我知道 Selenium 找到了该元素,但我无法检索文本。有趣的是,有人建议首先单击该值,然后尝试 getText(),因此当我尝试单击时,出现了异常:
org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
所以我想知道我是否无法检索文本值,因为它不可见?但是,如果是这种情况,我可以检索类属性、标签等内容,但不能检索文本值,这似乎很奇怪。
如有任何建议,我们将不胜感激。
HTML:
<body class=" ext-gecko ext-windows" onload="processLoaders();">
<script type="text/javascript">
<div id="topNavDiv" style="height: 90px">
<div id="bodyContentOuter" style="width: 1280px; height: 587px;">
<div id="bodyContentInner">
<script src="RLT/RLT.nocache.js" language="javascript" type="text/javascript">
<script defer="defer">
<script language="javascript" type="text/javascript">
<div id="rtcpMain" class=" x-component x-border-layout-ct" style="width: 1280px; height: 587px;">
<div id="rtcpMainWest" class=" x-panel x-component x-border-panel" style="left: 5px; top: 5px; width: 225px;">
<div id="x-auto-2" class=" x-tab-panel x-component x-border-panel" tabindex="0" hidefocus="true" style="left: 235px; top: 5px; width: 1040px;">
<div class="x-tab-panel-header x-unselectable" style="width: 1038px;" unselectable="on">
<div class="tone-rtcp-tabbed-content-panel" style="width: 1040px; height: 550px;">
<div id="x-auto-10" class=" x-component" style="overflow: auto; width: 1040px; height: 550px;">
<div id="QosDashboardPanel0" class=" x-panel x-component" style="width: 1040px;">
<div id="x-auto-13" class=" x-small-editor x-panel-header x-component x-hide-display" role="presentation">
<div id="rtcpDPBWrap" class="x-panel-bwrap" role="presentation" style="overflow: visible;">
<div class="x-panel-tbar x-panel-tbar-noheader" role="presentation" style="width: 1040px;">
<div id="rtcpDPBody" class="x-panel-body x-panel-body-noheader x-border-layout-ct" role="presentation" style="width: 1038px; height: 700px;">
<div id="QosDashboardPanelTop" class=" x-component x-border-panel x-border-layout-ct" style="left: 0px; top: 0px; width: 1038px; height: 400px;">
<div id="QosDashpardPanelBottom" class=" x-component x-border-panel x-border-layout-ct" style="left: 1px; top: 401px; width: 1036px; height: 298px;">
<div id="QosDashpardPanel_pqosChartsLC" class=" x-component x-border-panel x-border-layout-ct x-hide-display" style="left: 0px; top: 0px; width: 1036px; height: 400px;">
<div id="QosDashpardPanel_metricsTablesLC" class=" x-component x-border-panel x-border-layout-ct" style="left: 1px; top: 1px; width: 1034px; height: 296px;">
<div id="CollectorMetrics_toneletWrapper" class=" x-panel x-component x-border-panel" style="left: 1px; top: 1px; width: 330px;">
<div id="x-auto-99" class=" x-small-editor x-panel-header x-component x-hide-display" role="presentation">
<div class="x-panel-bwrap" role="presentation">
<div class="x-panel-body x-panel-body-noheader" role="presentation" style="width: 328px; height: 292px;">
<div id="CollectorMetrics" class=" x-panel x-component" style="width: 328px;">
<div id="x-auto-109" class=" x-small-editor x-panel-header x-component x-unselectable" role="presentation" unselectable="on">
<div class="x-panel-bwrap" role="presentation">
<div class="x-panel-body" role="presentation" style="width: 326px; height: 265px;">
<div id="CollectorQoSPerformanceMetricsgrid" class=" x-grid-panel x-component" style="position: relative; width: 326px; height: 265px;" tabindex="0" hidefocus="true" unselectable="">
<div class="x-grid3" role="presentation" style="width: 326px; height: 265px;">
<div class="x-grid3-viewport" role="presentation">
<div class="x-grid3-header" role="presentation">
<div class="x-grid3-scroller" role="presentation" style="width: 326px; height: 243px;">
<div class="x-grid3-body" role="presentation">
<div id="CollectorQoSPerformanceMetricsgrid_x-auto-633" class="x-grid3-row x-unselectable-single x-grid3-row-selected x-grid3-highlightrow " style="width:510px;">
<table class="x-grid3-row-table" cellspacing="0" cellpadding="0" border="0" style="width:510px;" role="presentation">
<tbody role="presentation">
<tr role="presentation">
<td id="x-auto-634" class="x-grid3-col x-grid3-cell x-grid3-td-name x-grid-cell-first " style="width:148px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-name" unselectable="on">
<u>Lync</u>
</div>
</td>
<td id="x-auto-635" class="x-grid3-col x-grid3-cell x-grid3-td-badCalls " style="width:53px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-badCalls" unselectable="on">36</div>
</td>
<td id="x-auto-636" class="x-grid3-col x-grid3-cell x-grid3-td-totalCalls " style="width:58px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-totalCalls" unselectable="on">120</div>
</td>
<td id="x-auto-637" class="x-grid3-col x-grid3-cell x-grid3-td-avgLatency " style="width:73px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-avgLatency" unselectable="on">223</div>
</td>
<td id="x-auto-638" class="x-grid3-col x-grid3-cell x-grid3-td-avgLoss " style="width:53px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-avgLoss" unselectable="on">0.80</div>
</td>
<td id="x-auto-639" class="x-grid3-col x-grid3-cell x-grid3-td-avgJitter " style="width:58px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-avgJitter" unselectable="on">29</div>
</td>
<td id="x-auto-640" class="x-grid3-col x-grid3-cell x-grid3-td-avgMOS x-grid3-cell-last " style="width:53px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-avgMOS" unselectable="on">3.86</div>
</td>
</tr>
</tbody>
</table>
</div>
<div id="CollectorQoSPerformanceMetricsgrid_x-auto-641" class="x-grid3-row x-unselectable-single " style="width:510px;">
<table class="x-grid3-row-table" cellspacing="0" cellpadding="0" border="0" style="width:510px;" role="presentation">
<tbody role="presentation">
<tr role="presentation">
<td id="x-auto-642" class="x-grid3-col x-grid3-cell x-grid3-td-name x-grid-cell-first " style="width:148px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-name" unselectable="on">
<u>CUCM-Publisher</u>
</div>
</td>
<td id="x-auto-643" class="x-grid3-col x-grid3-cell x-grid3-td-badCalls " style="width:53px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-badCalls" unselectable="on">3</div>
</td>
<td id="x-auto-644" class="x-grid3-col x-grid3-cell x-grid3-td-totalCalls " style="width:58px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-totalCalls" unselectable="on">52</div>
</td>
<td id="x-auto-645" class="x-grid3-col x-grid3-cell x-grid3-td-avgLatency " style="width:73px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-avgLatency" unselectable="on">190</div>
</td>
<td id="x-auto-646" class="x-grid3-col x-grid3-cell x-grid3-td-avgLoss " style="width:53px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-avgLoss" unselectable="on">0.79</div>
</td>
<td id="x-auto-647" class="x-grid3-col x-grid3-cell x-grid3-td-avgJitter " style="width:58px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-avgJitter" unselectable="on">31</div>
</td>
<td id="x-auto-648" class="x-grid3-col x-grid3-cell x-grid3-td-avgMOS x-grid3-cell-last " style="width:53px;" role="gridcell">
<div class="x-grid3-cell-inner x-grid3-col-avgMOS" unselectable="on">3.98</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
最佳答案
经过多次故障排除后,我发现我的 Xpath 上有一个小错误。来 self 的 html
<div id="QosDashboardPanel0" ...
我没有考虑多个选项卡。在我的 AUT 中,我打开了一个新选项卡,不是新的浏览器选项卡,而是应用程序本身的选项卡,整个 Hmtl 将保持不变,除了上面的代码片段将更改为
<div id="QosDashboardPanel1" ...
我假设 ID 不会改变,吸取教训!这就是为什么我遇到“无法单击不可见元素”的情况,该元素实际上在那里,但它隐藏在我的 Activity 选项卡后面。
这不是一个很好的解决方案,但我希望如果有人遇到类似的事情,这至少可以为他们指明正确的方向或敲响警钟。
关于java - 即使元素可见,WebElement getText() 返回空字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14844214/
我有一个 Web 应用程序,其中有几个使用 gettext 的翻译。但是现在我已经对应用程序进行了重大重写,虽然大多数字符串是相同的,但也有相当多的字符串被显着更改或删除。 我使用 xgettext
我开始尝试在 C 程序中翻译一些最常用的文本条目 使用 gettext,但在深入研究时,我得到了一点 对所有不同的文件格式有点困惑 因为功能上似乎有些重叠? 我想了解不同格式的概述 .po .pot
gettext 是否有办法警告我有关未包装在 _() 或 N_() 中的字符串? 基本上有没有一种方法可以获取所有不与 xgettext 使用的关键字匹配的字符串的列表。所以,我想要: ! xgett
我们正在使用 Gettext 翻译我们的网站,但最近我们发现我们的翻译团队存在一些问题。 我们有一些像... Hi Bob this evening you win *three* red *ball
我尝试运行 Homebrew 程序,以便在 5 月份的 mac 上安装一些 unix 工具,但开始时遇到问题。我已经删除了 fink 和 macports 并安装了 Homebrew 软件。 (我正在
是否可以使两个或多个 msgid 与一个 msgstr 匹配? 例如,('list.empty')和('list.empty') null') 返回“还没有任何对象。” 如果我在 po 文件中这样写:
所以,我一直在查看 getText() 方法,并且了解到它返回一个 CharSequence。所以你不能只这样做: TextView myTextView = (TextView) findViewB
我正在尝试 gettext 并运行 msginit --locale=en --input=messages.po这就是我所看到的: [... blah ...] Is the following y
我们目前正在国际化我们的平台。平台的代码库和基于该平台构建的产品非常庞大,并且有许多硬编码字符串(除了我们将标签等外部化的 UI)。 我需要一些关于使用 gettext 或 Java i18n 的建议
我用 gettext翻译我的用户界面。我想写符号 %作为字符串中 UI 标题的一部分,但由于它具有特殊含义,因此无法按预期工作。如何转义百分比符号? 最佳答案 使用 %%逃脱%。 关于gettext
我发现字符串 (msgid) 的翻译为空,所有 gettext 工具都会将该字符串视为未翻译。 有解决方法吗?我确实希望有一个空字符串作为此项目的翻译。 最佳答案 由于这似乎是 gettext 规范中
所以我注意到似乎有两种方法可以获取相同的数据,我不确定是否有关于何时应该使用其中任何一种的指南(除了绕过 getResources 可以节省内存,如果你实际上不想多次使用该对象)。但除此之外,我想知道
例如在下面的代码中a和b和c是相等的。 EditText editText; editText = (EditText) findViewById(R.id.edttxt); editText.set
我想从 9 X 9 网格中排列的 81 个文本字段中获取 int 形式的文本,但不想单独进行。我试图将它放在一个循环中,但问题是文本字段名称必须以 a[i][j] 形式显示。 for (i = 0;
我想使用 angular-gettext 在我的应用程序上实现 i18n,我遵循了这个 http://lostechies.com/gabrielschenker/2014/02/11/angular
我遵循了在 Windows 上安装 gettext 的指导,当我在命令提示符中键入 xgettext --version 时,它说它已安装。但是当我想运行这个命令时: python manage.py
所以我正在尝试让 phpmyadmin 在 Windows 7 上运行,我已经完成并安装了所有正确的程序/文件(apache、mySQL、php 等),我在右边有 phpmyadmin 文件夹放在我的
我正在尝试设置 phpMyAdmin,并且我正在关注此 site ,但我收到一个关于“ fatal error :在第 177 行调用 C:\Users\Jarek\mywebsite\phpMyAd
我需要解析我的 php 文件,其中使用了多个文本域。我只想解析一个特定的域(其他域已经被翻译)如何让 Poedit 做到这一点? 是否需要编译绑定(bind)到某个文本域的mo文件?如果是的话,如何在
当我尝试在 vala 中使用 gettext 时,我没有收到来自 vala 的错误或警告,但我从 c 编译器收到以下错误: /usr/include/glib-2.0/glib/gi18n-lib.h
我是一名优秀的程序员,十分优秀!