The dropdown menu will not be selected using Selenium Webdriver in Safari browser.
In Safari browser, I have to select an option from the dropdown, but the funny thing is that it works for all browsers except Safari on Mac OS. I am using Safari 10.0.3 with selenium webdriver version 3.3.0
I wrote the code in C #. See the code below -
IWebDriver driver;
driver = new SafariDriver();
List<string> handles = driver.WindowHandles.ToList<string>();
driver.SwitchTo().Window(handles.First());
driver.Navigate().GoToUrl("https://myip/MyPage.aspx");
SelectElement element = new SelectElement(driver.FindElement(By.Id("securityQuestion")));
int totalOptions = element.Options.Count;
Random rnd = new Random();
int rndValue = rnd.Next(1, totalOptions);
element.SelectByIndex(rndValue); // This is not working for Safari browser
driver.FindElement(By.Id("securityAnswer")).SendKeys("test");
driver.FindElement(By.Id("ctl00_Content_btnNext")).Click();
driver.Close();
The error does not occur because it does not select any value from the dropdown list.
+3
source to share
1 answer
This is a safari bug. The fix is ββon WebKit and tracked here: https://bugs.webkit.org/show_bug.cgi?id=174710
As a workaround, you can change which selection options are selected using JavaScript and the DOM API.
0
source to share