简体   繁体   English

点击按钮注册后如何切换到新打开的页面? C# Selenium 规格流

[英]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.

相关问题 单击按钮C#Selenium后无法切换到新的浏览器窗口 - Cannot Switch to new browser Window after click button C# Selenium 在 selenium 按钮单击 C# 中的变量后,如何分配复制到剪贴板的字符串? - How can I assign string copied to clipboard after selenium button click to a variable in C#? 硒和C#| 如何单击表格中的按钮? - Selenium & C# | How can I click a button in a table? C# 如何使用第 1 页中的按钮打开第 2 页? - C# How can i open page 2 with a button in page1? 如何单击链接并在新选项卡中打开它 Selenium WebDriver C# - How to click a link and open it in a new tab Selenium WebDriver C# 如何点击“新 <div> &#39;单击按钮后,哪个新生成? 在C#硒中 - how to click on 'new <div>' which newly generates after clicking on a button? in C# selenium Selenium C# - 如何在没有按钮名称和 ID 的情况下实现单击按钮 - Selenium C# - how can i implement click on button without button name and id 如何在ASP C#上打开新标签页,然后将焦点集中在当前页面上,然后单击按钮将当前页面重定向到另一个页面? - How to open new tab on ASP C# and focus stay on current page then current page redirect to another page on click button? Selenium + C#单击链接时如何切换Firefox的另一个选项卡,它将在另一个选项卡中打开? - Selenium + C# How to switch another Tab of Firefox when click a link and it will open in another tab? C# Selenium 如何实现没有 id 的点击按钮 - C# Selenium how can I implement click on button without id
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM