使用Selenium Webdriver Chrome和C#选择嵌套的iframe [英] Selecting nested iframe with selenium webdriver Chrome and C#
问题描述
我有一个框架,在其中单击按钮可打开一个iFrame.我的框架选择似乎可以正常工作,并且我知道我的XPath很好(因为它可以在chrome中工作),但是我的测试始终会因
I have a frame and inside that clicking a button opens an iFrame. my frame selection seems to work and i know my XPath is good (because it works in chrome) but my test always fails with
OpenQA.Selenium.WebDriverTimeoutException:5秒后超时---> OpenQA.Selenium.NoSuchElementException:无此类元素:无法找到元素:{"method":"xpath","selector":"//em [.='Job Selector']}
OpenQA.Selenium.WebDriverTimeoutException: Timed out after 5 seconds ---> OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//em[.='Job Selector']"}
随附一些显示HTML和源代码的图像.
attached are some images that show HTML and sources.
在我使用的代码中:
// 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']")));
关于我在做什么错的任何建议
Any suggestions on what I'm doing wrong
推荐答案
最后使它起作用:
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,没有运气
Without the body.click, no luck
Ja那教的道具: https://stackoverflow.com/a/41500131/1667188
这篇关于使用Selenium Webdriver Chrome和C#选择嵌套的iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!