找到元素。但在Sleenium中显示为未定位

时间:2018-01-12 11:00:04

标签: java xpath selenium-webdriver

有人可以请帮助我解决以下困惑: 想要在上一步中选择的拾取元素,如下面的屏幕截图所示

enter image description here

在webdriver中使用它:

List<WebElement> sport = driver.findElements(By.xpath("//div[@class='row tip-receipt']/div[@class='column large-6 tip-receipt-event']/dl/dd[1]"));

当使用在线工具检查xpath(这一个:http://videlibri.sourceforge.net/cgi-bin/xidelcgi)得到的结果如下面的截图所示:

enter image description here

并且,当在硒测试中使用它时,得到了这个结果:

 NoSuchElement no such element: Unable to locate element

我做错了什么? 提前谢谢

HTML是:

<div class="row">
<div class="column large-12 feedback">
<p class="feedback-item _07 warning">Feedback.section_not_completed</p>
</div>
</div>
<div class="row">
<div class="column large-12 text-center">
<div id="post-tip-loader-7" class="loader-large"><div>Loading..</div>    </div>
</div>
</div>
</div>
<div id="tip-post-analysis" class="tabbed-section" data-tab-title="3. Analysis">
<a style="position:absolute;top:10px;right:10px;z-index:2;" href="https://podio.com/webforms/6260741/487762" target="_blank">Report a bug</a>
<div class="row"><div class="column large-12"><h3 class="tabbed-section-  title">Analysis</h3></div></div>
<div class="row">
<div class="column large-12">
<input type="hidden" id="tip-oneliner" name="tip-oneliner" value="TIP ONELINER" data-counter="true">
</div>
</div>
<div class="row">
<div class="column large-12">
<label for="tip-analysis">Analysis</label>
<textarea class="has-wordcounter" id="tip-analysis" name="tip-analysis" data-counter="true" data-min-words="100" rows="15"></textarea>
</div>
</div>
<div class="row">
<div class="column large-12 feedback">
<p class="feedback-item _08 warning">The preview does not meet the 100 words-requirement.</p>
</div>
</div>
<div class="row">
<div class="column large-12">
<p>Tips must be exclusive. Rewrite your analysis if you've already made it available elsewhere online.</p>
</div>
</div>
<div class="row tip-receipt">
<div class="column large-6 tip-receipt-event">
<dl>
<dt>Event</dt>
<dd></dd>
<dd>, </dd>
<dd></dd>
<dd></dd>
</dl>
</div>
<div class="column large-6 tip-receipt-prediction">
<dl>
<dt>Prediction</dt>
<dd>Bet type: </dd>
<dd>Stake: </dd>
<dd>Odds: </dd>
<dd>Bookmaker: </dd>
</dl>
</div>
</div>
<div class="row">
<div class="column large-12 feedback">
<p class="feedback-item _09 warning">You must complete this section before proceeding onto the next step.</p>
</div>
</div>
<div class="row">
<div class="column large-12 text-center">
<div id="post-tip-loader-8" class="loader-large"><div>Loading..</div>    </div>
</div>
</div>
</div>
<div id="tip-post-upload" class="tabbed-section" data-tab-title="4. Publish">
<a style="position:absolute;top:10px;right:10px;z-index:2;" href="https://podio.com/webforms/6260741/487762" target="_blank">Report a bug</a>
<div class="row"><div class="column large-12"><h3 class="tabbed-section-title">Publish</h3></div></div>
<div class="row tip-receipt">
<div class="column large-6 tip-receipt-event" id="tplTipReceiptEvent">
<dl>
<dt>Event</dt>
<dd>{{sport}}</dd>
<dd>{{parentevent}}, {{country}}</dd>
<dd>{{event}}</dd>
<dd>{{eventtime}}</dd>
</dl>
</div>
<div class="column large-6 tip-receipt-prediction"  id="tplTipReceiptPrediction">
<dl>
<dt>Prediction</dt>
<dd>Bet type: {{bettype}}</dd>
<dd>Stake: {{stake}}</dd>
<dd>Odds: {{odds}}</dd>
<dd>Bookmaker: {{bookmaker}}</dd>
</dl>
</div>

1 个答案:

答案 0 :(得分:0)

由于您没有提及HTML,并且没有信息,如果有任何框架,我仍在尝试答案。

如果有任何帧,则需要先打开该帧,然后才能获得值

如果您重复使用d1标签,则可以尝试XPATH,如下所示:

(//div[@class='row tip-receipt']/div[@class='column large-6 tip-receipt-event']/dl)[1]