在树视图中使用 XPath 查找元素
本文关键字:XPath 查找 元素 视图 | 更新日期: 2023-09-27 17:56:33
我有这个html,我需要在Visual Studio中使用Selenium WebDriver单击{Syców}{3002}。请帮忙。我有那个 xpath,但这不起作用。
我的路径:
ClickElementByXPath("//div[@id='ctl00_ctl00_ContentPlaceHolderCenter_ContentPlaceHolderBody_UpdatePanel1']/div[2]/div[2]/div/div/table/tbody/tr/td/div/div/table/tbody/tr[4]/td/a/font/b");
.HTML
<?IMPORT NAMESPACE = TVNS IMPLEMENTATION = "http://192.168.3.11/webctrl_client/1_0/treeview.htc" DECLARENAMESPACE />
<tvns:treeview tabIndex=0 id=ctl00_ctl00_ContentPlaceHolderCenter_ContentPlaceHolderBody_nitNetworkItem_ctl14 hideFocus style="OVERFLOW-X: auto" onfirequeuedevents="javascript: window.setTimeout('__doPostBack(''ctl00$ctl00$ContentPlaceHolderCenter$ContentPlaceHolderBody$nitNetworkItem$ctl14'','''')', 0, 'JavaScript')" onselectedindexchange="javascript: if (event.oldTreeNodeIndex != event.newTreeNodeIndex) this.queueEvent('onselectedindexchange', event.oldTreeNodeIndex + ',' + event.newTreeNodeIndex)" oncheck="javascript: if (this.clickedNodeIndex != null) this.queueEvent('oncheck', this.clickedNodeIndex)" oncollapse="javascript: if (this.clickedNodeIndex != null) this.queueEvent('oncollapse', this.clickedNodeIndex)" onexpand="javascript: if (this.clickedNodeIndex != null) this.queueEvent('onexpand', this.clickedNodeIndex)" systemImagesPath="/webctrl_client/1_0/treeimages/" HelperID="__ctl00_ctl00_ContentPlaceHolderCenter_ContentPlaceHolderBody_nitNetworkItem_ctl14_State__" selectedNodeIndex="0" HoverNodeIndex __scrollLeft="0" __scrollTop="0">
<tvns:treenodetype Type="folder" ImageUrl="/webctrl_client/1_0/Images/energetics/folder.gif">
</tvns:treenodetype>
<tvns:treenodetype Type="folderGPZ" ImageUrl="/webctrl_client/1_0/Images/energetics/folder.gif">
</tvns:treenodetype>
<tvns:treenodetype Type="137" ImageUrl="/webctrl_client/1_0/Images/energetics/gpz.gif" ExpandedImageUrl="/webctrl_client/1_0/Images/energetics/gpz - set.gif">
</tvns:treenodetype>
<tvns:treenodetype Type="137a" ImageUrl="/webctrl_client/1_0/Images/energetics/gpz A.gif" ExpandedImageUrl="/webctrl_client/1_0/Images/energetics/gpz - set A.gif">
</tvns:treenodetype>
<tvns:treenodetype Type="137w" ImageUrl="/webctrl_client/1_0/Images/energetics/gpz W.gif" ExpandedImageUrl="/webctrl_client/1_0/Images/energetics/gpz - set W.gif">
</tvns:treenodetype>
<tvns:treenodetype Type="2" ImageUrl="/webctrl_client/1_0/Images/energetics/stacja.gif" ExpandedImageUrl="/webctrl_client/1_0/Images/energetics/stacja - set.gif">
</tvns:treenodetype>
<tvns:treenodetype Type="2a" ImageUrl="/webctrl_client/1_0/Images/energetics/stacja A.gif" ExpandedImageUrl="/webctrl_client/1_0/Images/energetics/stacja - set A.gif">
</tvns:treenodetype>
<tvns:treenodetype Type="2w" ImageUrl="/webctrl_client/1_0/Images/energetics/stacja W.gif" ExpandedImageUrl="/webctrl_client/1_0/Images/energetics/stacja - set W.gif">
</tvns:treenodetype>
<tvns:treenodetype Type="23" ImageUrl="/webctrl_client/1_0/Images/energetics/Ciag.gif" ExpandedImageUrl="/webctrl_client/1_0/Images/energetics/Ciag - set.gif">
</tvns:treenodetype>
<tvns:treenodetype Type="23a" ImageUrl="/webctrl_client/1_0/Images/energetics/Ciag A.gif" ExpandedImageUrl="/webctrl_client/1_0/Images/energetics/Ciag - set A.gif">
</tvns:treenodetype>
<tvns:treenodetype Type="23w" ImageUrl="/webctrl_client/1_0/Images/energetics/Ciag W.gif" ExpandedImageUrl="/webctrl_client/1_0/Images/energetics/Ciag - set W.gif">
</tvns:treenodetype>
<tvns:treenodetype Type="245" ImageUrl="/webctrl_client/1_0/Images/energetics/Ciag.gif" ExpandedImageUrl="/webctrl_client/1_0/Images/energetics/Ciag - set.gif">
</tvns:treenodetype>
<tvns:treenodetype Type="245a" ImageUrl="/webctrl_client/1_0/Images/energetics/Ciag A.gif" ExpandedImageUrl="/webctrl_client/1_0/Images/energetics/Ciag - set A.gif">
</tvns:treenodetype>
<tvns:treenodetype Type="245w" ImageUrl="/webctrl_client/1_0/Images/energetics/Ciag W.gif" ExpandedImageUrl="/webctrl_client/1_0/Images/energetics/Ciag - set W.gif">
</tvns:treenodetype>
<tvns:treenodetype Type="D" ImageUrl="/webctrl_client/1_0/Images/energetics/Default.gif" ExpandedImageUrl="/webctrl_client/1_0/Images/energetics/Default - set.gif">
</tvns:treenodetype>
<tvns:treenodetype Type="Da" ImageUrl="/webctrl_client/1_0/Images/energetics/Default A.gif" ExpandedImageUrl="/webctrl_client/1_0/Images/energetics/Default - set A.gif">
</tvns:treenodetype>
<tvns:treenodetype Type="Dw" ImageUrl="/webctrl_client/1_0/Images/energetics/Default W.gif" ExpandedImageUrl="/webctrl_client/1_0/Images/energetics/Default - set W.gif">
</tvns:treenodetype>
<tvns:treenode Type="folder" Expanded="True" NodeData="0$0$0$False$False$False" ID="#0$0$0$False$False$False#">
GPZ
<tvns:treenode Type="137" NodeData="137$4300434171$43$False$False$False" CheckBox="False" ID="#137$4300434171$43$False$False$False#">
{<b>PZ/RS Wojciechowo</b>}{<b>0700</b>}
</tvns:treenode>
<tvns:treenode Type="137" NodeData="137$4300432739$43$False$False$False" CheckBox="False" ID="#137$4300432739$43$False$False$False#">
{<b>Kępno</b>}{<b>3001</b>}
</tvns:treenode>
<tvns:treenode Type="137" NodeData="137$4300432740$43$False$False$False" CheckBox="False" ID="#137$4300432740$43$False$False$False#">
{<b>Syców</b>}{<b>3002</b>}
</tvns:treenode>
<tvns:treenode Type="137" NodeData="137$4300432741$43$False$False$False" CheckBox="False" ID="#137$4300432741$43$False$False$False#">
{<b>Wieruszów</b>}{<b>3003</b>}
</tvns:treenode>
<tvns:treenode Type="137" NodeData="137$4300501049$43$False$False$False" CheckBox="False" ID="#137$4300501049$43$False$False$False#">
{<b>Kępno Wsch.</b>}{<b>3004</b>}
</tvns:treenode>
<tvns:treenode Type="137" NodeData="137$4300499223$43$False$False$False" CheckBox="False" ID="#137$4300499223$43$False$False$False#">
{<b>Obcy</b>}{<b>9999</b>}
</tvns:treenode>
</tvns:treenode>
</tvns:treeview>
假设 ID 是唯一的 ClickElementByXPath("//*[@id='#137$4300432740$43$False$False$False#']");
ClickElementById("ctl00_ctl00_ContentPlaceHolderCenter_ContentPlaceHolderBody_nitNetworkItem_ctl14");
Thread.Sleep(1000);
ClickElementById("ctl00_ctl00_ContentPlaceHolderCenter_ContentPlaceHolderBody_btnNetworkItemChoose");
This is half solved, because i dont know how click something else than "Syców".