![](/img/trans.png)
[英]Unable to locate element -- OpenQA.Selenium.NoSuchElementException
[英]OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element C# Find By Class
Message:
Test method CFSSOnlineBanking.SmokeTests.TransferDisplay threw exception:
OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#menuLeftRailContainer > div:nth-child(1) > div:nth-child(3)"}
(Session info: chrome=91.0.4472.164)
Stack Trace:
RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
RemoteWebDriver.FindElement(String mechanism, String value)
RemoteWebDriver.FindElementByCssSelector(String cssSelector)
<>c__DisplayClass23_0.<CssSelector>b__0(ISearchContext context)
By.FindElement(ISearchContext context)
RemoteWebDriver.FindElement(By by)
TransferPage.get_TransferLink() line 22
SmokeTests.TransferDisplay() line 57
我目前正在嘗試單擊位於 div 內的 href。 無論我嘗試什么,似乎都無法點擊它。
我嘗試添加等待 我嘗試通過 LinkText、PartialLinkText、cssSelector 和 xPATH 單擊
目前我在 TransferPage 類中有這個:
public IWebElement TransferLink => _driver.FindElement(By.CssSelector("#menuLeftRailContainer > div:nth-child(1) > div:nth-child(3)"));
然后在我的實際測試方法中,我有:
_driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
transferPage.TransferLink.Click();
你可以試試下面的
路徑:
//a[@href='/connect-native/transfer/']
或 css 選擇器
a[href='/connect-native/transfer/']
在代碼中:
public IWebElement TransferLink => _driver.FindElement(By.CssSelector("a[href='/connect-native/transfer/']"));
導致您在代碼中使用的 css 選擇器看起來有點亂。 你確定有 1/1 匹配的元素嗎?
如果這不起作用,您能在您的網頁中查找 iframe 嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.