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 \
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