简体   繁体   English

使用带有C#的Selenium Webdriver在弹出窗口中找不到元素

[英]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. if(IsElementPresent(By.CssSelector(“#FirstName”)))....我正在通过CssSelector检查元素。 I tried xpath then also same exception I am getting. 我尝试了xpath然后也遇到了同样的异常。 I am unable to find any other element(including first name) on that pop up.Please suggest me solution. 我无法在该弹出窗口中找到其他任何元素(包括名字)。请向我建议解决方案。 Thanks in advance!!! 提前致谢!!!

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
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.

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