Hello
While using selenium webdriver i found out that there is no straight forward method to select values from dropdown.Then i found out below solution to resolve this issue:
First identify the dropdown element by its Id or name etc. Then using SelectElement method we can directly select the dropdown element using text as below:
IWebElement expiryMonth = Driver.FindElement(By.Id("CreditCard_ExpiryDate_Month"));
SelectElement selectExpiryMonth = new SelectElement(expiryMonth);
selectExpiryMonth.SelectByText("December");
The above operation is very easy in fluent automation. As name suggests its very fluent :-)
I.Select("2007").From("#PassedOut);
Where 2007 is the value in the dropdown and #PassedOut is the id of the dropdown field. We can use class name identifier as well. So three lines of code can be done in single line using fluent automation.
We can even make use of jQuery selectors to identify the elements. Chrome provides a nice support to test you jQuery selectors under watch expressions tab (under Sources) in developers mode.
Thanks
Nishant
While using selenium webdriver i found out that there is no straight forward method to select values from dropdown.Then i found out below solution to resolve this issue:
First identify the dropdown element by its Id or name etc. Then using SelectElement method we can directly select the dropdown element using text as below:
IWebElement expiryMonth = Driver.FindElement(By.Id("CreditCard_ExpiryDate_Month"));
SelectElement selectExpiryMonth = new SelectElement(expiryMonth);
selectExpiryMonth.SelectByText("December");
The above operation is very easy in fluent automation. As name suggests its very fluent :-)
I.Select("2007").From("#PassedOut);
Where 2007 is the value in the dropdown and #PassedOut is the id of the dropdown field. We can use class name identifier as well. So three lines of code can be done in single line using fluent automation.
We can even make use of jQuery selectors to identify the elements. Chrome provides a nice support to test you jQuery selectors under watch expressions tab (under Sources) in developers mode.
Thanks
Nishant
No comments:
Post a Comment