我在C#中使用Selenium点击一个叫做“Store Locator”的链接。我当前的代码如下所示,但没有单击链接:
IWebElement storeLink = driver.FindElement(By.LinkText("Store Locator"));这是原始的HTML,注意标签中嵌套了一个span元素,不确定这是否有区别。
<a href="/site/olspage.jsp?id=cat12090&type=page&rdct=n" data-lid="hdr_stl"><span class="header-icon-storeFinder" aria-hidden="true"></span>Store Locator</a>发布于 2015-05-30 01:40:19
看起来链接是隐藏的。即使Selenium找到了链接,它也不能直接交互。在这种情况下,JavaScript是您唯一的选择
By xpath = By.XPath("//span[contains(text(),'Store Locator')]");
IWebelement element = driver.FindElement(xpath);
((IJavaScriptExecutor)driver).ExecuteScript(@"arguments[0].click();",element);发布于 2015-07-07 00:28:24
这肯定会起作用。
IWebElement storeLink = driver.FindElement(By.LinkText("Store Locator"));
storeLink.click();https://stackoverflow.com/questions/30535679
复制相似问题