Selenium WebDriver with Appium - Not able to Select value from drop down box having onchange javascript function in iOS simulator

I am using Selenium Webdriver with appium to automate mobile web application in iOS simulator. I am unable to select the value from drop down box using the below code.

Select dropdownbox = new Select(driver.findElement(By.id("alertType"));
dropdownbox.selectByVisibleText("Alert");

Below is the html of the drop down box which is having javascript function “onchange”

<select id="alertType" onchange="populate();" name="alertType"> 

Above selenium webdriver code working perfectly in all browsers but it is not able to select value in iOS simulator. Is this because of drop down having ‘onchange’ javascript function? Can any one provide the solution for this problem?

Thanks in Advance!!

Try click on the drop down first and then select the option. The option in drop down will be a separate element.

I have tried clicking the drop down and tried to click on the option element using xpath “//option[text()=‘Alert’]”, But it is not clicking the specific option.

Also i have tried as shown below

WebElement dropdown = driver.findElement(By.xpath("//select[@id=‘alertType’]"));
dropdown.click();

Select d1 = new Select(dropdown);
d1.selectByVisibleText(“Alert”);

But both are not working. This problem is only for iOS Simulator. It is working perfectly with all browsers.
Can anyone help me in this who are faced the similar issue and solved the problem?

Can you please send me UIAutomator screenshot?

I am automating a mobile web app. Below is the html of the element.

<select id="alertType" onchange="populate();" name="alertType">

I have observed that any element which triggers javascript function, webdriver is unable to perform operation on that element, I have found same issue with radio button in another page of my web application which triggers javascript function upon selecting the radio button, below is the html of the radio button.

<input type="radio" onclick="enableSubmit();" value="Y" name="PayAgree">

It is giving exception as given below:-

org.openqa.selenium.WebDriverException: An error occurred while executing user supplied JavaScript.   

    (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.20 seconds
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 02:56:46'
System info: host: 'xxxxxxxx', ip: '1.1.2.1', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.1', java.version: '1.7.0_79'
Session ID: 8ee0d625-5d36-4734-b7e8-e7a9b9590546
Driver info: org.openqa.selenium.remote.RemoteWebDriver

Below is the code i am using:-

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "iPad 2");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("platformVersion", "8.4");
capabilities.setCapability("browserName", "Safari");
capabilities.setCapability("nativeWebTap", true);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
 //Create an instance of RemoteWebDriver and connect to the Appium server.
driver = new RemoteWebDriver(new URL("http://localhost:4723/wd/hub"), capabilities);

Appium version :- 1.4.0
Selenium WebDriver - 2.47.1
iOS Simulator - IPad 2

Please Help!!

You need to switch the context for finding the hybrid/mobile-web app elements. For more information:

http://appium.io/slate/en/master/?java#automating-hybrid-ios-apps