I have web application,It works only in edge browser with IE mode.In that I am unable to automate drop-down field,So I need code to automate the drop-down field using selenium web driver.
Asked
Active
Viewed 64 times
0
-
You muyst provide a [Minimum Reproducible Code](https://stackoverflow.com/help/minimal-reproducible-example) for someone to take a look at the issue and provide a solution. Thanks – Anand Gautam Apr 11 '22 at 08:39
-
Does [this](https://stackoverflow.com/a/51252175/7429447) or [this](https://stackoverflow.com/a/69996687/7429447) discussion helps you? – undetected Selenium Apr 11 '22 at 08:45
-
I am using selectByVisibleText method – Testing Apr 11 '22 at 09:10
1 Answers
0
If I understood what are you looking for... I wrote it in C#.
using OpenQA.Selenium.Support.UI
IWebElement dropdownElement = driver.FindElement(By.Name("country code"));
//create select element object
SelectElement selectElement = new SelectElement(dropdownElement);
//select by value
selectElement.SelectByValue("NIR");
// select by text
selectElement.SelectByText("Northern Ireland");

Alexandru Bucur
- 76
- 3
-
-
@Testing however it is the same, the only thing that changes are the names of the methods, which instead of starting with an uppercase letter start with a lowercase one. First you have to import the selenium support library, so is something like 'import org.openqa.selenium.support.ui.Select' – Alexandru Bucur Apr 11 '22 at 09:26
-
-
-
It depends on the web application front end technology, I might be wrong but no one give you the desired answer without seeing some code, error, HTML. – Akzy Apr 11 '22 at 09:29
-
@Testing can you paste some HTML code here of the dropdown element? – Alexandru Bucur Apr 11 '22 at 09:35
-
@AlexandruBucur As I mentioned above our application work In Edge browser with IE mode there Right click is disabled we cannot inspect element, So I can't get HTML code. – Testing Apr 11 '22 at 09:48
-
@Testing shortcut is CTRL+SHIFT+J on Windows, CMD+OPT+J on Mac – Alexandru Bucur Apr 11 '22 at 09:57
-
@AlexandruBucur I did that, I am getting "Developer tools are not available in internet explorer mode to debug the page open the page in IEChooser" – Testing Apr 11 '22 at 10:14
-
-
@Testing I have modified my answer in order to select Northern Ireland from the select element: first retrieve the web element by name (in this case, the select element's name is country code), then there are 2 ways that do basically the same thing, the first one selects the Norther Ireland option by option value, the second one by the text. try it and let me know. – Alexandru Bucur Apr 11 '22 at 11:58
-
@AlexandruBucuri wrote below code WebElement obj = getObject(strLocator); Select dd = new Select(obj); try{ dd.selectByVisibleText(value); }catch(Expection e){ dd.selectByVisibleText(Value.toUpperCase()); } This is not working because Value is "Northern Ireland" as first letter is capital and rest small its failing and also I tired to remove try and catch and wrote dd.selectByVisibleText(Northern Ireland) It throws Nosuchmethodexception. – Testing Apr 14 '22 at 07:44