【发布时间】:2019-02-26 22:19:15
【问题描述】:
我是 C# 新手,但在定位元素时遇到问题。我不太明白如何找到相对的 xpath。我正在尝试找到一个元素。我的代码如下:
IWebElement webElement = driver.FindElement(By.XPath("Nothing I put here works"));
Thread.Sleep(1000);
IJavaScriptExecutor executor = (IJavaScriptExecutor)driver;
这是我要查找的内容:
<li _ngcontent-c2="" class="header-item person-search ng-tns-c2-1 ng-star-inserted" ngbdropdown="" ngbtooltip="Person Search" placement="left">
<a _ngcontent-c2="" class="dropdown-toggle dropdown-toggle" aria-haspopup="true" href="javascript:void(0)" ngbdropdowntoggle="" aria-expanded="false">
<span _ngcontent-c2="" class="fa fa-search-plus block"></span>
</a>
</li>
【问题讨论】:
-
我强烈建议您将
"Nothing I put here works"替换为您所做的实际尝试(并且可能显示多次尝试以确保人们知道尝试了什么)。这样,更容易在方法调用中查明问题。 -
我认为为您的页面上传整个 HTML 会很有帮助。
标签: c# selenium xpath css-selectors webdriverwait