[英]How can I switch to the new open page after click button register? C# Selenium specflow
so I'm a newbie in C# selenium and I faced one problem(issue) I create several steps on one main page after I add information on the registration page I click to "register button" and this redirects me to the next new page, and my test cases failed.所以我是 C# selenium 的新手,我遇到了一个问题(问题)我在注册页面上添加信息后在一个主页上创建了几个步骤我点击“注册按钮”,这会将我重定向到下一个新页面,我的测试用例失败了。 Because my webDriver is still on the previous page.
因为我的webDriver还在上一页。 But I should find a new element on a new page.
但是我应该在新页面上找到一个新元素。 How can I do it more simple way?
我怎样才能更简单地做到这一点? Thank you in advance.
先感谢您。
[When(@"I add specific name")]
public void WhenIAddSpecificName()
{
namelField.Click();
namelField.Clear();
Random randomName = new Random();
int randomNumName = randomName.Next(0, 10000);
namelField.SendKeys($"IK" + randomNumName);
Thread.Sleep(3000);
}
[Then(@"I click registration button")]
public void ThenIClickRegistrationButton()
{
registrationButton.Click();
webDriver.SwitchTo().Window(webDriver.WindowHandles[1]);
}
[When(@"I add mobile telephone no")]
public void WhenIAddMobileTelephoneNo()
{
phoneField.Click();
phoneField.SendKeys("2222");
Thread.Sleep(5000);
webDriver.Close();
}
I want to find a new element on the new page.我想在新页面上找到一个新元素。
I would probably get all the handles before switching to it using driver.WindowHandles
在使用
driver.WindowHandles
切换到它之前,我可能会获得所有句柄
So once you've performed a click then you should use the below code:因此,一旦您执行了点击,您就应该使用以下代码:
registrationButton.Click();
List<string> winodws = new List<string>(driver.WindowHandles);
driver.SwitchTo().Window(winodws[1]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.