简体   繁体   English

OpenQA.Selenium.NoSuchElementException:没有这样的元素:无法定位元素 C# 按类查找

[英]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

I am currently trying to click on a href that is located inside a div.我目前正在尝试单击位于 div 内的 href。 No matter what I try it seems like I cannot click on it.无论我尝试什么,似乎都无法点击它。 在此处输入图片说明

Here is the element when I inspect it.这是我检查时的元素。 在此处输入图片说明

I have tried adding a wait I have tried clicking by LinkText, PartialLinkText, cssSelector and xPATH我尝试添加等待 我尝试通过 LinkText、PartialLinkText、cssSelector 和 xPATH 单击

Currently I have this in my TransferPage Class:目前我在 TransferPage 类中有这个:

public IWebElement TransferLink => _driver.FindElement(By.CssSelector("#menuLeftRailContainer > div:nth-child(1) > div:nth-child(3)"));

And then in my actual test method I have:然后在我的实际测试方法中,我有:

_driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
transferPage.TransferLink.Click();

Can you try with the following你可以试试下面的

xpath :路径:

//a[@href='/connect-native/transfer/']

or css selector或 css 选择器

a[href='/connect-native/transfer/'] 

In code :在代码中:

public IWebElement TransferLink => _driver.FindElement(By.CssSelector("a[href='/connect-native/transfer/']"));

cause the css selector you have used in your code, looks bit messy.导致您在代码中使用的 css 选择器看起来有点乱。 Are you sure there is 1/1 matching element with that ?你确定有 1/1 匹配的元素吗?

if this does not work, can you look for iframes in your webpage ?如果这不起作用,您能在您的网页中查找 iframe 吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法定位元素——OpenQA.Selenium.NoSuchElementException - Unable to locate element -- OpenQA.Selenium.NoSuchElementException OpenQA.Selenium.NoSuchElementException:&#39;无法找到元素&#39; - OpenQA.Selenium.NoSuchElementException: 'Unable to locate element' OpenQA.Selenium.NoSuchElementException:使用 Selenium 和 C# 在页面上定位元素时出现无法定位元素错误 - OpenQA.Selenium.NoSuchElementException: Unable to locate element error while locating an element on a page using Selenium and C# OpenQA.Selenium.NoSuchElementException: '没有这样的元素 c# - OpenQA.Selenium.NoSuchElementException: 'no such element c# OpenQA.Selenium.NoSuchElementException:无法找到ID为的元素 - OpenQA.Selenium.NoSuchElementException :Unable to find element with id OpenQA.Selenium.NoSuchElementException:没有这样的元素 - OpenQA.Selenium.NoSuchElementException : no such element OpenQA.Selenium.NoSuchElementException - C# Selenium - OpenQA.Selenium.NoSuchElementException - C# Selenium C#Selenium SelectByIndex OpenQA.Selenium.NoSuchElementException:&#39;无法找到索引为1的选项&#39; - C# Selenium SelectByIndex OpenQA.Selenium.NoSuchElementException: 'Cannot locate option with index: 1' c#硒中的用户代码未处理OpenQA.Selenium.NoSuchElementException - OpenQA.Selenium.NoSuchElementException was unhandled by user code in c# selenium Selenium 在 C# 程序中抛出“OpenQA.Selenium.NoSuchElementException” - Selenium throws “OpenQA.Selenium.NoSuchElementException” in C# program
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM