Selenium Webdriver C# Sendkeys (Keys.Arrowdown)

后端 未结 5 1918
傲寒
傲寒 2021-02-14 20:14

I\'m trying to do do an arrow using Selenium Webdriver/C# compile but when I try to compile I get this error:

\'Keys\' is an ambiguous reference between \

相关标签:
5条回答
  • 2021-02-14 20:42

    Try this

    IWebDriver driver = new ChromeDriver();
    driver.Navigate().GoToUrl("http:www.google.com");
    IWebElement MyElement = driver.FindElement(By.Name("q"));
    MyElement.SendKeys(Keys.ArrowUp); MyElement.SendKeys(Keys.ArrowDown);

    0 讨论(0)
  • 2021-02-14 20:50

    I can provide you two realizations, but the first one works only locally:

    1. Element.SendKeys(OpenQA.Selenium.Keys.ArrowUp);

    2. char c = '\uE013'; // ASCII code ArrowUp

      Element.SendKeys(Convert.ToString(c));

    0 讨论(0)
  • 2021-02-14 21:02

    I would suggest to do next:

        IWebElement element = driver.FindElement(By.Id("ctl00_PlaceHolderMain_ctrlChangeBillingAddress_ctrlChangeBillingAddress_txtBillingAddress"));
        OpenQA.Selenium.Interactions.Actions action = new OpenQA.Selenium.Interactions.Actions(driver);
        action.SendKeys(element, Keys.Down).SendKeys(element, Keys.Enter).Build().Perform();
    
    0 讨论(0)
  • 2021-02-14 21:06

    Same was happening to my code too. Like in my registration from, 1. I had an Address fields that picks up the entered address from google search and then fills the fields accordingly such as: Sub-urb, city , post code etc. 2. There was a button to attach a file (like browse from desktop and select any image or document to attach) I got error "'Keys' is an ambiguous reference between OpenQA.Selenium.Keys and 'System.Windows.Forms.Keys' (CS0104) Then I realized that it means there are two different Keys types in two different namespaces. Coz for address selection, my code was :

    driver.FindElement(By.XPath("//*[@id='PostalAddress_Address']")).SendKeys(Address); //Address to select from autofill and fill textboxes accordingly
            Thread.Sleep(500);
            driver.FindElement(By.XPath("//*[@id='PostalAddress_Address']")).SendKeys(Keys.ArrowDown);
            driver.FindElement(By.XPath("//*[@id='PostalAddress_Address']")).SendKeys(Keys.Enter);
    

    and for Attach file the code was:

    //Select and attach file from the computer
            driver.FindElement(By.XPath("//*[@id='graduate-education']/div[4]/label")).Click(); //Click Attach file button
            Thread.Sleep(500);
            //driver.FindElement(By.XPath("//*[@id='graduate-education']/div[4]/label")).SendKeys(AttachFile);
            SendKeys.SendWait(@"Complete File Path"); //Select the file from the location
            Thread.Sleep(500);
            SendKeys.SendWait(@"{Enter}"); 
    

    Namespaces added were:

        using OpenQA.Selenium; using System; using System.Threading; using System.Windows.Forms;
    

    Because of - Keys type was not recognising from where it actually belong, so I had to change the code of address fields and use OpenQA.Selenium.keys.ArrowDown as below:

    driver.FindElement(By.XPath("//*[@id='PostalAddress_Address']")).SendKeys(Address); //Address to select from autofill and fill textboxes accordingly
            Thread.Sleep(500);
            driver.FindElement(By.XPath("//*[@id='PostalAddress_Address']")).SendKeys(OpenQA.Selenium.Keys.ArrowDown);
            driver.FindElement(By.XPath("//*[@id='PostalAddress_Address']")).SendKeys(OpenQA.Selenium.Keys.Enter);
    

    This worked for me, hope the same for you too

    0 讨论(0)
  • 2021-02-14 21:07

    As the error states, there are two different Keys types in two different namespaces.

    You need to unambiguously qualify the type by writing OpenQA.Selenium.Keys.

    0 讨论(0)
提交回复
热议问题