How to select values in dropdownlist with selenium?
up vote
2
down vote
favorite
I am using selenium, testng and java with ecplipse to perform an automated test. I'm having success with commands like click on a button (selenium.click ("button"), pass values to textboxes (selenium.type ("component", "value") and clicks too, but when it comes with a component type dropdownlist (relating to common or asp.net mvc) I can not select the field with the command seleniu. select ("field", "value").
To select the values and even the fields, I am using xpath to it, but even so, with the dropdownlist can not, or can partially.
When a dropdownlist accept the value I type, I can use the selenium.click but if not, nothing I've tried so far does not.
java selenium selenium-webdriver selenium-rc testng
add a comment |
up vote
2
down vote
favorite
I am using selenium, testng and java with ecplipse to perform an automated test. I'm having success with commands like click on a button (selenium.click ("button"), pass values to textboxes (selenium.type ("component", "value") and clicks too, but when it comes with a component type dropdownlist (relating to common or asp.net mvc) I can not select the field with the command seleniu. select ("field", "value").
To select the values and even the fields, I am using xpath to it, but even so, with the dropdownlist can not, or can partially.
When a dropdownlist accept the value I type, I can use the selenium.click but if not, nothing I've tried so far does not.
java selenium selenium-webdriver selenium-rc testng
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am using selenium, testng and java with ecplipse to perform an automated test. I'm having success with commands like click on a button (selenium.click ("button"), pass values to textboxes (selenium.type ("component", "value") and clicks too, but when it comes with a component type dropdownlist (relating to common or asp.net mvc) I can not select the field with the command seleniu. select ("field", "value").
To select the values and even the fields, I am using xpath to it, but even so, with the dropdownlist can not, or can partially.
When a dropdownlist accept the value I type, I can use the selenium.click but if not, nothing I've tried so far does not.
java selenium selenium-webdriver selenium-rc testng
I am using selenium, testng and java with ecplipse to perform an automated test. I'm having success with commands like click on a button (selenium.click ("button"), pass values to textboxes (selenium.type ("component", "value") and clicks too, but when it comes with a component type dropdownlist (relating to common or asp.net mvc) I can not select the field with the command seleniu. select ("field", "value").
To select the values and even the fields, I am using xpath to it, but even so, with the dropdownlist can not, or can partially.
When a dropdownlist accept the value I type, I can use the selenium.click but if not, nothing I've tried so far does not.
java selenium selenium-webdriver selenium-rc testng
java selenium selenium-webdriver selenium-rc testng
edited Nov 11 at 3:11
Cœur
17.3k9102142
17.3k9102142
asked Jul 7 '13 at 13:45
Elton da Costa
57227
57227
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
up vote
2
down vote
using webdriver you can do it with Select class i have posted a code which was working below please
have a look on that,Select Class had api to select the drop down values by its index as well as value,have a look on Select api for more info
public static void dropdown()
WebDriver driver = new FirefoxDriver();
driver.get("http://demosthenes.info/blog/166/HTML-Forms-Drop-down-Menus");
Select sele = new Select(driver.findElement(By.id("state")));
sele.selectByIndex(1);
Sorry this is not gonna work. Select class only works for elements with <select> tags which is not the case for asp.net. I am trying to find the solution for this problem as well, but no luck so far...
– Lucas
Dec 12 '13 at 13:37
@Lucas if possible please post your html dom so that we can also help you to solve the problem
– Devi Kiran
Feb 28 '14 at 10:06
thanks, but it's been a long time ago and I don't have anymore...
– Lucas
Feb 28 '14 at 15:08
add a comment |
up vote
0
down vote
WebElement select = driver.findElement(By.id("selection"));
List<WebElement> options = select.findElements(By.tagName("option"));
for (WebElement option : options)
if("Germany".equals(option.getText()))
option.click();
add a comment |
up vote
0
down vote
Actions actions = new Actions(driver);
WebElement dBox1= (new WebDriverWait(driver,10)).until(ExpectedConditions.elementToBeClickable(By.id("selection""))). selectByVisibleText("");
actions.moveToElement(dBox1);
actions.click();
actions.perform();
add a comment |
up vote
0
down vote
You have to use Select in selenium to select from the drop down value.
//by ID
WebDriver driver = new FirefoxDriver();
new Select (driver.findElement(By.id("usState"))).selectByVisibleText("FL");
//by XPath
new Select (driver.findElement(By.xpath("xPath for dropdown"))).selectByVisibleText("FL");
add a comment |
up vote
0
down vote
There are several ways to select elements from dropdown list. Below are some of them you can keep them as common drop-down operation and call what ever method you need.
//select the dropdown using "select by visible text"
public static void dropDownSelectByText(WebElement webElement, String VisibleText)
Select selObj=new Select(webElement);
selObj.selectByVisibleText(VisibleText);
//select the dropdown using "select by index"
public static void dropDownSelectByIndex(WebElement webElement, int IndexValue)
Select selObj=new Select(webElement);
selObj.selectByIndex(IndexValue);
//select the dropdown using "select by value"
public static void dropDownSelectByValue(WebElement webElement, String Value)
Select selObj=new Select(webElement);
selObj.selectByValue(Value);
You can call above methods like
CommonPageOperations.dropDownSelectByValue(selectSubClientFromDropDownXpath,strSubClientName);
Drop down list appear only if mouse move to specific location, Then you have to use Actions as well
public void mouseMoveToExpandIcon()
Actions action = new Actions(driver);
action.moveToElement(expandButtonXpath).perform();
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f17512702%2fhow-to-select-values-in-dropdownlist-with-selenium%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
using webdriver you can do it with Select class i have posted a code which was working below please
have a look on that,Select Class had api to select the drop down values by its index as well as value,have a look on Select api for more info
public static void dropdown()
WebDriver driver = new FirefoxDriver();
driver.get("http://demosthenes.info/blog/166/HTML-Forms-Drop-down-Menus");
Select sele = new Select(driver.findElement(By.id("state")));
sele.selectByIndex(1);
Sorry this is not gonna work. Select class only works for elements with <select> tags which is not the case for asp.net. I am trying to find the solution for this problem as well, but no luck so far...
– Lucas
Dec 12 '13 at 13:37
@Lucas if possible please post your html dom so that we can also help you to solve the problem
– Devi Kiran
Feb 28 '14 at 10:06
thanks, but it's been a long time ago and I don't have anymore...
– Lucas
Feb 28 '14 at 15:08
add a comment |
up vote
2
down vote
using webdriver you can do it with Select class i have posted a code which was working below please
have a look on that,Select Class had api to select the drop down values by its index as well as value,have a look on Select api for more info
public static void dropdown()
WebDriver driver = new FirefoxDriver();
driver.get("http://demosthenes.info/blog/166/HTML-Forms-Drop-down-Menus");
Select sele = new Select(driver.findElement(By.id("state")));
sele.selectByIndex(1);
Sorry this is not gonna work. Select class only works for elements with <select> tags which is not the case for asp.net. I am trying to find the solution for this problem as well, but no luck so far...
– Lucas
Dec 12 '13 at 13:37
@Lucas if possible please post your html dom so that we can also help you to solve the problem
– Devi Kiran
Feb 28 '14 at 10:06
thanks, but it's been a long time ago and I don't have anymore...
– Lucas
Feb 28 '14 at 15:08
add a comment |
up vote
2
down vote
up vote
2
down vote
using webdriver you can do it with Select class i have posted a code which was working below please
have a look on that,Select Class had api to select the drop down values by its index as well as value,have a look on Select api for more info
public static void dropdown()
WebDriver driver = new FirefoxDriver();
driver.get("http://demosthenes.info/blog/166/HTML-Forms-Drop-down-Menus");
Select sele = new Select(driver.findElement(By.id("state")));
sele.selectByIndex(1);
using webdriver you can do it with Select class i have posted a code which was working below please
have a look on that,Select Class had api to select the drop down values by its index as well as value,have a look on Select api for more info
public static void dropdown()
WebDriver driver = new FirefoxDriver();
driver.get("http://demosthenes.info/blog/166/HTML-Forms-Drop-down-Menus");
Select sele = new Select(driver.findElement(By.id("state")));
sele.selectByIndex(1);
answered Jul 8 '13 at 5:59
Devi Kiran
4281416
4281416
Sorry this is not gonna work. Select class only works for elements with <select> tags which is not the case for asp.net. I am trying to find the solution for this problem as well, but no luck so far...
– Lucas
Dec 12 '13 at 13:37
@Lucas if possible please post your html dom so that we can also help you to solve the problem
– Devi Kiran
Feb 28 '14 at 10:06
thanks, but it's been a long time ago and I don't have anymore...
– Lucas
Feb 28 '14 at 15:08
add a comment |
Sorry this is not gonna work. Select class only works for elements with <select> tags which is not the case for asp.net. I am trying to find the solution for this problem as well, but no luck so far...
– Lucas
Dec 12 '13 at 13:37
@Lucas if possible please post your html dom so that we can also help you to solve the problem
– Devi Kiran
Feb 28 '14 at 10:06
thanks, but it's been a long time ago and I don't have anymore...
– Lucas
Feb 28 '14 at 15:08
Sorry this is not gonna work. Select class only works for elements with <select> tags which is not the case for asp.net. I am trying to find the solution for this problem as well, but no luck so far...
– Lucas
Dec 12 '13 at 13:37
Sorry this is not gonna work. Select class only works for elements with <select> tags which is not the case for asp.net. I am trying to find the solution for this problem as well, but no luck so far...
– Lucas
Dec 12 '13 at 13:37
@Lucas if possible please post your html dom so that we can also help you to solve the problem
– Devi Kiran
Feb 28 '14 at 10:06
@Lucas if possible please post your html dom so that we can also help you to solve the problem
– Devi Kiran
Feb 28 '14 at 10:06
thanks, but it's been a long time ago and I don't have anymore...
– Lucas
Feb 28 '14 at 15:08
thanks, but it's been a long time ago and I don't have anymore...
– Lucas
Feb 28 '14 at 15:08
add a comment |
up vote
0
down vote
WebElement select = driver.findElement(By.id("selection"));
List<WebElement> options = select.findElements(By.tagName("option"));
for (WebElement option : options)
if("Germany".equals(option.getText()))
option.click();
add a comment |
up vote
0
down vote
WebElement select = driver.findElement(By.id("selection"));
List<WebElement> options = select.findElements(By.tagName("option"));
for (WebElement option : options)
if("Germany".equals(option.getText()))
option.click();
add a comment |
up vote
0
down vote
up vote
0
down vote
WebElement select = driver.findElement(By.id("selection"));
List<WebElement> options = select.findElements(By.tagName("option"));
for (WebElement option : options)
if("Germany".equals(option.getText()))
option.click();
WebElement select = driver.findElement(By.id("selection"));
List<WebElement> options = select.findElements(By.tagName("option"));
for (WebElement option : options)
if("Germany".equals(option.getText()))
option.click();
edited Jul 9 '13 at 9:56
Vince Bowdren
4,26221840
4,26221840
answered Jul 8 '13 at 9:55
Archana Singh
643
643
add a comment |
add a comment |
up vote
0
down vote
Actions actions = new Actions(driver);
WebElement dBox1= (new WebDriverWait(driver,10)).until(ExpectedConditions.elementToBeClickable(By.id("selection""))). selectByVisibleText("");
actions.moveToElement(dBox1);
actions.click();
actions.perform();
add a comment |
up vote
0
down vote
Actions actions = new Actions(driver);
WebElement dBox1= (new WebDriverWait(driver,10)).until(ExpectedConditions.elementToBeClickable(By.id("selection""))). selectByVisibleText("");
actions.moveToElement(dBox1);
actions.click();
actions.perform();
add a comment |
up vote
0
down vote
up vote
0
down vote
Actions actions = new Actions(driver);
WebElement dBox1= (new WebDriverWait(driver,10)).until(ExpectedConditions.elementToBeClickable(By.id("selection""))). selectByVisibleText("");
actions.moveToElement(dBox1);
actions.click();
actions.perform();
Actions actions = new Actions(driver);
WebElement dBox1= (new WebDriverWait(driver,10)).until(ExpectedConditions.elementToBeClickable(By.id("selection""))). selectByVisibleText("");
actions.moveToElement(dBox1);
actions.click();
actions.perform();
answered Nov 22 '13 at 5:51
Amirdha
679113367
679113367
add a comment |
add a comment |
up vote
0
down vote
You have to use Select in selenium to select from the drop down value.
//by ID
WebDriver driver = new FirefoxDriver();
new Select (driver.findElement(By.id("usState"))).selectByVisibleText("FL");
//by XPath
new Select (driver.findElement(By.xpath("xPath for dropdown"))).selectByVisibleText("FL");
add a comment |
up vote
0
down vote
You have to use Select in selenium to select from the drop down value.
//by ID
WebDriver driver = new FirefoxDriver();
new Select (driver.findElement(By.id("usState"))).selectByVisibleText("FL");
//by XPath
new Select (driver.findElement(By.xpath("xPath for dropdown"))).selectByVisibleText("FL");
add a comment |
up vote
0
down vote
up vote
0
down vote
You have to use Select in selenium to select from the drop down value.
//by ID
WebDriver driver = new FirefoxDriver();
new Select (driver.findElement(By.id("usState"))).selectByVisibleText("FL");
//by XPath
new Select (driver.findElement(By.xpath("xPath for dropdown"))).selectByVisibleText("FL");
You have to use Select in selenium to select from the drop down value.
//by ID
WebDriver driver = new FirefoxDriver();
new Select (driver.findElement(By.id("usState"))).selectByVisibleText("FL");
//by XPath
new Select (driver.findElement(By.xpath("xPath for dropdown"))).selectByVisibleText("FL");
answered Apr 22 '14 at 20:41
SamK
169720
169720
add a comment |
add a comment |
up vote
0
down vote
There are several ways to select elements from dropdown list. Below are some of them you can keep them as common drop-down operation and call what ever method you need.
//select the dropdown using "select by visible text"
public static void dropDownSelectByText(WebElement webElement, String VisibleText)
Select selObj=new Select(webElement);
selObj.selectByVisibleText(VisibleText);
//select the dropdown using "select by index"
public static void dropDownSelectByIndex(WebElement webElement, int IndexValue)
Select selObj=new Select(webElement);
selObj.selectByIndex(IndexValue);
//select the dropdown using "select by value"
public static void dropDownSelectByValue(WebElement webElement, String Value)
Select selObj=new Select(webElement);
selObj.selectByValue(Value);
You can call above methods like
CommonPageOperations.dropDownSelectByValue(selectSubClientFromDropDownXpath,strSubClientName);
Drop down list appear only if mouse move to specific location, Then you have to use Actions as well
public void mouseMoveToExpandIcon()
Actions action = new Actions(driver);
action.moveToElement(expandButtonXpath).perform();
add a comment |
up vote
0
down vote
There are several ways to select elements from dropdown list. Below are some of them you can keep them as common drop-down operation and call what ever method you need.
//select the dropdown using "select by visible text"
public static void dropDownSelectByText(WebElement webElement, String VisibleText)
Select selObj=new Select(webElement);
selObj.selectByVisibleText(VisibleText);
//select the dropdown using "select by index"
public static void dropDownSelectByIndex(WebElement webElement, int IndexValue)
Select selObj=new Select(webElement);
selObj.selectByIndex(IndexValue);
//select the dropdown using "select by value"
public static void dropDownSelectByValue(WebElement webElement, String Value)
Select selObj=new Select(webElement);
selObj.selectByValue(Value);
You can call above methods like
CommonPageOperations.dropDownSelectByValue(selectSubClientFromDropDownXpath,strSubClientName);
Drop down list appear only if mouse move to specific location, Then you have to use Actions as well
public void mouseMoveToExpandIcon()
Actions action = new Actions(driver);
action.moveToElement(expandButtonXpath).perform();
add a comment |
up vote
0
down vote
up vote
0
down vote
There are several ways to select elements from dropdown list. Below are some of them you can keep them as common drop-down operation and call what ever method you need.
//select the dropdown using "select by visible text"
public static void dropDownSelectByText(WebElement webElement, String VisibleText)
Select selObj=new Select(webElement);
selObj.selectByVisibleText(VisibleText);
//select the dropdown using "select by index"
public static void dropDownSelectByIndex(WebElement webElement, int IndexValue)
Select selObj=new Select(webElement);
selObj.selectByIndex(IndexValue);
//select the dropdown using "select by value"
public static void dropDownSelectByValue(WebElement webElement, String Value)
Select selObj=new Select(webElement);
selObj.selectByValue(Value);
You can call above methods like
CommonPageOperations.dropDownSelectByValue(selectSubClientFromDropDownXpath,strSubClientName);
Drop down list appear only if mouse move to specific location, Then you have to use Actions as well
public void mouseMoveToExpandIcon()
Actions action = new Actions(driver);
action.moveToElement(expandButtonXpath).perform();
There are several ways to select elements from dropdown list. Below are some of them you can keep them as common drop-down operation and call what ever method you need.
//select the dropdown using "select by visible text"
public static void dropDownSelectByText(WebElement webElement, String VisibleText)
Select selObj=new Select(webElement);
selObj.selectByVisibleText(VisibleText);
//select the dropdown using "select by index"
public static void dropDownSelectByIndex(WebElement webElement, int IndexValue)
Select selObj=new Select(webElement);
selObj.selectByIndex(IndexValue);
//select the dropdown using "select by value"
public static void dropDownSelectByValue(WebElement webElement, String Value)
Select selObj=new Select(webElement);
selObj.selectByValue(Value);
You can call above methods like
CommonPageOperations.dropDownSelectByValue(selectSubClientFromDropDownXpath,strSubClientName);
Drop down list appear only if mouse move to specific location, Then you have to use Actions as well
public void mouseMoveToExpandIcon()
Actions action = new Actions(driver);
action.moveToElement(expandButtonXpath).perform();
edited Nov 15 at 7:39
answered Nov 15 at 7:31
SDK_90
214
214
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f17512702%2fhow-to-select-values-in-dropdownlist-with-selenium%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown