[英]Unable to find the Element on the pop up using Selenium Webdriver with C#
namespace ABC.ABCManager.UIAutomation.Authorization
{
[TestClass]
public class VerifyCreateUsersSendInvite : BaseTest
{
[TestMethod]
public void VerifySendAnInviteLink()
{
Actions actions = new Actions(driver);
selectAndClickOnCustomerName();
Thread.Sleep(3000);
try
{
//Click Send an Invite link
var LinksOnOverview = driver.FindElements(By.CssSelector(".popupFrameLink.summary-tool-link"));
LinksOnOverview[2].Click();
//Verification point to see "Send an Invite" link has opened by checking "TextName" textbox is present or not by using CSS selector
if (IsElementPresent(By.CssSelector("#FirstName")))
{
ExtentManager.verifySafely(driver.FindElement(By.CssSelector("#FirstName")).TagName, "input", "VerifySendAnInviteLink", "link has opened ", driver);
Console.WriteLine("'Send an Invite' link has opened ");
}
}
catch (Exception ex)
{
driver.Close();
}
}
}
}
在上面的代碼中,我單擊“發送邀請”鏈接,然后,在該行上得到異常“找不到元素”:
if(IsElementPresent(By.CssSelector(“#FirstName”)))....我正在通過CssSelector檢查元素。 我嘗試了xpath然后也遇到了同樣的異常。 我無法在該彈出窗口中找到其他任何元素(包括名字)。請向我建議解決方案。 提前致謝!!!
可能您應該更改尋找元素的框架
ReadOnlyCollection<string> windowHandles = driver.WindowHandles;
driver.SwitchTo().Window(windowHandles[1]);
// ELEMENTS on Second frame (window)
driver.SwitchTo().Window(windowHandles[0]);
// ELEMENTS on First Frame
try
{
List<IWebElement> frames = new List<IWebElement>(driver.FindElements(By.TagName("iframe")));
driver.SwitchTo().Frame(1);
//Verification point to see "Send an Invite" link has opened by checking Text Name textbox is present or not by using CSS selector
if (IsElementPresent(By.CssSelector("#FirstName")))
{
ExtentManager.verifySafely(driver.FindElement(By.CssSelector("#FirstName")).TagName, "input", "VerifySendAnInviteLink", "link has opened ", driver);
Console.WriteLine("'Send an Invite' link has opened ");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.