本文介绍了如何使用selenium C#控制网页内的窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好b $ b我使用selenium c#代码来管理网页。我已经设法在firefox中打开一个网页登录到网页并在这个网页中打开一个子窗口。
但是我无法控制这个网页中的子窗口。 br />
我试图使用
HiI am using selenium c# code to manage a web-page. I have managed to open a web-page in firefox login to the web-page and open a child window in this web-page.
But I can not control the child window inside this web page.
I tried to use
PopupWindowFinder
代码:
code:
finder = new PopupWindowFinder(driver,timeout,sleepInterval);
try {
popUpWindow = finder.Click(driver.FindElement(By.XPath("//li[@class='quicklink icHumanResources']")));
}
catch (WebDriverException)
{
System.Threading.Thread.Sleep(10);
}
driver.SwitchTo().Window(popUpWindow);
但它不起作用。
我尝试过:
But it does not work.
What I have tried:
driver = new FirefoxDriver();
driver.Navigate().GoToUrl("https://WEB-ADDRESS/");
IWebElement userName = driver.FindElement(By.XPath("//input[@class='LoginIputField focus']"));
IWebElement password = driver.FindElement(By.Id("Engine_LoginScreen_txtPassword"));
IWebElement loginButton = driver.FindElement(By.Id("Engine_LoginScreen_btnSubmit"));
userName.SendKeys("XXXXXXXXXXXX");
password.SendKeys("XXXXXXXXXXXXXXXXXXXXX");
loginButton.Click();
System.Threading.Thread.Sleep(20000);
ITakesScreenshot ssdriver = driver as ITakesScreenshot;
Screenshot screenshot = ssdriver.GetScreenshot();
string timestamp = DateTime.Now.ToString("yyyy-MM-dd-hhmmss");
screenshot.SaveAsFile("D:\\SLIKA" + @"\Exception-"+timestamp+".png", System.Drawing.Imaging.ImageFormat.Png);
string currentHandle = driver.CurrentWindowHandle;
System.Threading.Thread.Sleep(20000);
TimeSpan timeout = new TimeSpan(0, 1, 0);
TimeSpan sleepInterval = new TimeSpan(0, 1, 0);
finder = new PopupWindowFinder(driver,timeout,sleepInterval);
try {
popUpWindow = finder.Click(driver.FindElement(By.XPath("//li[@class='quicklink icHumanResources']")));
}
catch (WebDriverException)
{
System.Threading.Thread.Sleep(10);
}
driver.SwitchTo().Window(popUpWindow);
推荐答案
driver.SwitchTo().Frame(<This has 3 overrides>);
干杯
肖恩
Cheers
Sean
这篇关于如何使用selenium C#控制网页内的窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!