繁体   English   中英

此元素的 Xpath 或 Css 选择器 - 帮助

[英]Xpath or Css selector for this element - HELPP

我花了大约 5 个小时试图在那里找到该成功消息的选择器,用于我的 Selenium c# 测试,但运气不佳。 我的测试总是失败,说找不到元素!!

知道我可以使用什么选择器吗???

我已经尝试了所有插件的 xpath、Css、Classname ......

 public IWebElement alertSuccessfulAlert => WebDriver.FindElement(By.XPath("//div[contains(text(),'Registration is successful')]")); public IWebElement alertSuccessfulAlert => WebDriver.FindElement(By.CssSelector("body:nth-child(2) my-app:nth-child(1) div.container:nth-child(2) > main.row:nth-child(1)"));

在此处输入图片说明 在此处输入图片说明

气泡消息注册成功是通过JavaScript生成的,因此您必须为所需的ElementToBeClickable()引入WebDriverWait ,您可以使用以下任一定位器策略

  • XPath

     public IWebElement alertSuccessfulAlert = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//div[contains(., 'Registration is successful')]")));

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM