S.S.N
S.S.N

Reputation: 29

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();
        }
    }
}
}

In above code,I am clicking link "Send an Invitation" and after that, I am getting exception "Element not found" on the line :
if (IsElementPresent(By.CssSelector("#FirstName"))) .... I am inspecting element by CssSelector. I tried xpath then also same exception I am getting. I am unable to find any other element(including first name) on that pop up.Please suggest me solution. Thanks in advance!!!

Upvotes: 1

Views: 1820

Answers (2)

S.S.N
S.S.N

Reputation: 29

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 ");
                }

Upvotes: 1

qchar90
qchar90

Reputation: 474

Probably you should change frame on which you looking for elements

ReadOnlyCollection<string> windowHandles = driver.WindowHandles;
driver.SwitchTo().Window(windowHandles[1]);
// ELEMENTS on Second frame (window)
driver.SwitchTo().Window(windowHandles[0]);
// ELEMENTS on First Frame

Upvotes: 1

Related Questions