希望你真的很好并且可以帮助我解决这个简短的问题。
我试图找到以下对象 id=C39_W133_V136_thtmlb_button_27
但使用位于跨度之后的文本 (text = "Edit")。请问我尝试了不同的方法,但到目前为止还没有成功,有什么想法吗?
<a href="javascript:void(0)" class="th-bt th-bt-icontext-dis icon-font" tabindex="-1" oncontextmenu="return false;" ondragstart="return false;" id="C39_W133_V136_thtmlb_button_27">
::before
<img class="th-bt-img" src="/SAP/BC/BSP/SAP/thtmlb_styles/sap_skins/belize/images/1x1.png">
<span class="th-bt-span"><b class="th-bt-b">Edit</b></span>
<b class="th-bt-b">Edit</b>
</a>
最佳答案
为了使用元素中包含的文本来定位元素,唯一的选择是使用 XPath。
//a[./b[.='Edit']]
^ Start at the top of the document and find an A tag
^ ...that has a descendant B tag
^ ...that contains the text 'Edit'
关于python - Xpath Selenium-如何通过子文本定位元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63819414/