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