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 \
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);
I can provide you two realizations, but the first one works only locally:
Element.SendKeys(OpenQA.Selenium.Keys.ArrowUp);
char c = '\uE013'; // ASCII code ArrowUp
Element.SendKeys(Convert.ToString(c));
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();
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
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
.