私は左手メニューのウェブページを持っています。多くのdivタグで構成されています。 Selenium Pythonスクリプトが実行されているときに、左のメニューからクリックしたいテキストをクリックしていないことがわかりました。それは何か他のものをクリックしています。 Xpathが正しくありません。私はそれは正しいテキスト「統計をクリックされていない親のdivのテキスト「分析」Selenium Python Xpath多くのネストされたdivタグから正しいスパンテキストを選択する方法
を持っているテキスト「統計」を(それがのdiv \ spanタグである)を見つけたい
"HTMLソースのどこかに別の"統計 "があるかもしれないからです。 「」という文字が「分析」のテキストであるとから始まる場合は、「統計」のテキストを見つけて、正しい要素を取得します。
私のXPathは次のとおりです。
.//div//span[@title="Analysis"]/following::div[5]//span[text()="Statistics"]
HTMLは次のとおりです。
<div>
<span class="" title="Analysis"
style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;">Analysis</span>
</div>
</div>
</div>
</div>
</div>
<div style="overflow: hidden;">
<div>
<div>
<div aria-selected="false" role="treeitem" aria-setsize="3" aria-posinset="1" aria-expanded="false"
aria-level="2">
<div class="GJPPK2LBIF" style="padding-left: 16px;">
<div class="GJPPK2LBIF GJPPK2LBKF" style="padding-left: 16px;position:relative;" onclick="">
<div class="GJPPK2LBJF" style="left: 0px;width: 15px;height: 15px;position:absolute;">
<img border="0"
style="width:15px;height:15px;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA7/HbnjJn53wAAAABJRU5ErkJggg==) no-repeat 0px 0px;"
src="http://test1:8080/clearcore/ClearCore/clear.cache.gif"
onload="this.__gwtLastUnhandledEvent=" load";"/>
</div>
<div class="GJPPK2LBLF">
<div style="padding-left: 22px;position:relative;zoom:1;">
<div style="left:0px;margin-top:-8px;position:absolute;top:50%;line-height:0px;">
<img border="0"
style="width:16px;height:16px;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaekJggg==) no-repeat 0px 0px;"
src="http://test1:8080/clearcore/ClearCore/clear.cache.gif"
onload="this.__gwtLastUnhandledEvent=" load";"/>
</div>
<div>
<span class="" title="Statistics"
style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;">Statistics</span>
</div>
</div>
</div>
</div>
</div>
</div>
おかげで、 リアズ
私は混乱している、それは働いているかどうか? – Guy
これはあなたの質問に答えることはできませんが、私はあなたのXPathを考えています。これはかなり厳格で、このため、いくつかのdivで遊んだからこそ、このテストの可能性が増します。 –
Chromeのxpathヘルパーを検討する - https://chrome.google.com/webstore/detail/xpath-helper/hgimnogjllphhhkhlmebbmlgjoejdpjl?hl=ja - これを使用すると、一致するものを表示したり、既存の要素のxpathをコピーして貼り付けたりすることができます –