使用Microsoft Edge驱动程序单击Selenium. [英] Selenium click using Microsoft Edge Driver.

查看:169
本文介绍了使用Microsoft Edge驱动程序单击Selenium.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参见下面的图片.我尝试使用Selenium通过以下方法选择输入标签:

 -element.Click();
 -element.SendKeys(Keys.Enter);
 - 动作action =新的Actions(Browser.Driver).MoveToElement(element);
    action.Click().Perform();

我试图通过具有以下代码的代码中的属性返回它来单击复选框:

Please see pic below. I have tried to select the input tag through the following method using Selenium:

 - element.Click();
 - element.SendKeys(Keys.Enter);
 -  Actions action = new Actions(Browser.Driver).MoveToElement(element);
   action.Click().Perform();

I am trying to click the checkbox by returning it through a property in code that has the following code:

 WebDriverWait wait = new WebDriverWait(Browser.Driver, TimeSpan.FromSeconds(60));
                IWebElement checkbox = wait.Until(ExpectedConditions.ElementExists((By.CssSelector("label[for='PerformerIndependence_AcceptTermsAndConditions']"))));
                return checkbox;



 WebDriverWait wait = new WebDriverWait(Browser.Driver, TimeSpan.FromSeconds(60));
                IWebElement checkbox = wait.Until(ExpectedConditions.ElementExists((By.CssSelector("input#PerformerIndependence_AcceptTermsAndConditions"))));
                return checkbox;

由于某种原因,如果我在调试模式下运行代码以测试返回的元素,请单击它.  如果我只是使用Visual Studio2015在运行模式下运行测试,则不会选中该复选框.  使用元素点击进行三次尝试的方法 包装在try/catch块中.请帮忙!!!

For some reason If I run the code in debug mode to test the element returned to click it will click.  If I just run my test in run mode using Visual Studio2015, the checkbox is not clicked.  The method using the element to click for the three attempts is wrapped in a try/catch block. Please help!!!


推荐答案

  嗨Antwan Maddox,

 Hi Antwan Maddox,

>>>如果我只是使用Visual Studio2015在运行模式下运行测试,则不会单击该复选框.

 >>If I just run my test in run mode using Visual Studio2015, the checkbox is not clicked.

运行模式是什么意思?我已将您的代码运行在我的身边,没有任何问题.这是我的代码,如果我误解了您的问题,请随时告诉我.

What is your meaning of run mode? I have run your coded in my side without any problems. Here is my code, if I misunderstand your issue, please feel free to let me know.

        public IWebElement getElement(IWebDriver drive)
        {
            WebDriverWait wait = new WebDriverWait(drive, TimeSpan.FromSeconds(60));
            IWebElement checkbox = wait.Until(ExpectedConditions.ElementExists((By.CssSelector("input#PerformerIndependence_AcceptTermsAndConditions"))));
            return checkbox;
        }
        static void Main(string[] args)
        {
            //RemoteWebDriver driver= new InternetExplorerDriver();//IE
            RemoteWebDriver driver = new EdgeDriver(@"C:\Users\Administrator\Desktop");
            try
            {
               
                Program p = new Program();
                driver.Navigate().GoToUrl("http://10.7.17.134/test.html");
                Thread.Sleep(1000);
                IWebElement checkBox = p.getElement(driver);
                checkBox.Click();
                Thread.Sleep(3000);
                checkBox.SendKeys(OpenQA.Selenium.Keys.Enter);
                Actions action = new Actions(driver);
                action.MoveToElement(checkBox).Click().Perform();         
                Thread.Sleep(3000);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                driver.Quit();
                Console.ReadLine();
            }
        }

此致

奥斯卡


这篇关于使用Microsoft Edge驱动程序单击Selenium.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆