使用selenium webdriver Chrome和C#

时间:2017-07-20 17:15:15

标签: selenium-webdriver

我有一个框架,在里面单击按钮可打开iFrame。我的框架选择似乎工作,我知道我的XPath是好的(因为它适用于chrome)但我的测试总是失败

OpenQA.Selenium.WebDriverTimeoutException:5秒后超时---> OpenQA.Selenium.NoSuchElementException:没有这样的元素:无法定位元素:{"方法":" xpath","选择器":" // em [。='工作选择器']"}

附有一些显示HTML和来源的图片。

在我的代码中我使用:

 // wait for menu frame to appear
        wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.XPath("//frame[@id='menu']")));


        // do a bunch of stuff

        driver.SwitchTo().DefaultContent();
        wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.XPath("//frame[@id='master']")));




        // Add to running jobs: open iFrame
        driver.FindElement(By.Id("ctl00_cphMain_cmdAdd")).Click();



        //driver.SwitchTo().DefaultContent(); tried with and without this
        wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.XPath("//iframe[@name='JobWindow']")));



        // wait for SelectJob Window to appear tried several elements
        //wait.Until(ExpectedConditions.ElementIsVisible(By.Id("RadWindowWrapper_ctl00_cphMain_JobWindow")));
        wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//em[.='Job Selector']")));

关于我做错的任何建议

enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

最后让这个工作:

 wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.XPath("//iframe[@name='JobWindow']")));
            IWebElement body = driver.FindElement(By.TagName("body"));
            body.Click();


            // wait for SelectJob Window to appear
             IWebElement SaveButton = wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("cmdSave")));  
            SaveButton.Click();

没有body.click,没有运气

转向耆那教的道具:https://stackoverflow.com/a/41500131/1667188