Xpath / Selenium - How do I grab all of the options in a , excluding the default, given a simple dom?How to select option in drop down protractorjs e2e testsHow to select these elements with Xpath?XPath contains(text(),'some string') doesn't work when used with node with more than one Text subnodeSelenium IDE and xpath - find text / row in table and select radio boxHow to select text input by typed text in xpath?XPath: Default to 'Node A', select 'Node B' instead if 'Node B' is not emptyFastest way to select an option using selenium?Using XPath how do I select a node() at a specific position that is also text()?Selenium not selecting select option due to javascript call backHow to get text content first preceding and following text node in DOM using given xpath?How to construct a xpath expression with variable for Selenium in python using %s
Bullying boss launched a smear campaign and made me unemployable
How do I exit BASH while loop using modulus operator?
Does the Idaho Potato Commission associate potato skins with healthy eating?
What exactly is ineptocracy?
Can a virus destroy the BIOS of a modern computer?
OP Amp not amplifying audio signal
How to remove border from elements in the last row?
One verb to replace 'be a member of' a club
Is it a bad idea to plug the other end of ESD strap to wall ground?
What historical events would have to change in order to make 19th century "steampunk" technology possible?
What are the G forces leaving Earth orbit?
files created then deleted at every second in tmp directory
Is it possible to map the firing of neurons in the human brain so as to stimulate artificial memories in someone else?
Can compressed videos be decoded back to their uncompresed original format?
How do conventional missiles fly?
Knowledge-based authentication using Domain-driven Design in C#
Did 'Cinema Songs' exist during Hiranyakshipu's time?
Ambiguity in the definition of entropy
How many wives did king shaul have
Do Iron Man suits sport waste management systems?
How to find if SQL server backup is encrypted with TDE without restoring the backup
What reasons are there for a Capitalist to oppose a 100% inheritance tax?
Do creatures with a listed speed of "0 ft., fly 30 ft. (hover)" ever touch the ground?
How obscure is the use of 令 in 令和?
Xpath / Selenium - How do I grab all of the options in a , excluding the default, given a simple dom?
How to select option in drop down protractorjs e2e testsHow to select these elements with Xpath?XPath contains(text(),'some string') doesn't work when used with node with more than one Text subnodeSelenium IDE and xpath - find text / row in table and select radio boxHow to select text input by typed text in xpath?XPath: Default to 'Node A', select 'Node B' instead if 'Node B' is not emptyFastest way to select an option using selenium?Using XPath how do I select a node() at a specific position that is also text()?Selenium not selecting select option due to javascript call backHow to get text content first preceding and following text node in DOM using given xpath?How to construct a xpath expression with variable for Selenium in python using %s
Working on an automation test using codeceptjs/selenium, I need to read the text of the nodes of a select drop down without knowing what they will be ahead of time and excluding the greyed out default option (since the app will not function until a choice is made).
<select id="itemname1">
<option class="greydefault">How Many?</option>
<option>6</option>
<option>8</option>
<option>10</option>
<option>12</option>
</select>
<select id="itemname2">
<option class="greydefault">What Type?</option>
<option>a</option>
<option>b</option>
<option>c</option>
<option>d</option>
</select>
Given the above simple dom, question is how to write an xpath that grab all 4 of the option nodes that contain 6 8 10 and 12. And another xpath that returns all 4 of the option nodes a b c and d.
Here are my attempts that don't work for me:
.//option/preceding::option[text()="What Type?"]/following::option[text()="How Many?"]
.//option/following::option[text()="How Many?"]/preceding::option[text()="What Type?"]
.//option/preceding::option[text()="What Type?"] and following::option[text()="How Many?"]
.//option/[preceding::option[text()="What Type?"] and following::option[text()="How Many?"]]
The first 2 attempts returns only the node "How many" for me, and the next attempts are invalid.
The output of the xpath query should return each option node other than the default node.
That xpath is put into a function that reads the texts of the nodes, it looks like this:
getElementsText(locator)
let driver = this.helpers.Protractor.browser;
return driver.element.all(locator).getAttribute("textContent").then((result) =>
return result.toString().split(',');
);
selenium xpath
add a comment |
Working on an automation test using codeceptjs/selenium, I need to read the text of the nodes of a select drop down without knowing what they will be ahead of time and excluding the greyed out default option (since the app will not function until a choice is made).
<select id="itemname1">
<option class="greydefault">How Many?</option>
<option>6</option>
<option>8</option>
<option>10</option>
<option>12</option>
</select>
<select id="itemname2">
<option class="greydefault">What Type?</option>
<option>a</option>
<option>b</option>
<option>c</option>
<option>d</option>
</select>
Given the above simple dom, question is how to write an xpath that grab all 4 of the option nodes that contain 6 8 10 and 12. And another xpath that returns all 4 of the option nodes a b c and d.
Here are my attempts that don't work for me:
.//option/preceding::option[text()="What Type?"]/following::option[text()="How Many?"]
.//option/following::option[text()="How Many?"]/preceding::option[text()="What Type?"]
.//option/preceding::option[text()="What Type?"] and following::option[text()="How Many?"]
.//option/[preceding::option[text()="What Type?"] and following::option[text()="How Many?"]]
The first 2 attempts returns only the node "How many" for me, and the next attempts are invalid.
The output of the xpath query should return each option node other than the default node.
That xpath is put into a function that reads the texts of the nodes, it looks like this:
getElementsText(locator)
let driver = this.helpers.Protractor.browser;
return driver.element.all(locator).getAttribute("textContent").then((result) =>
return result.toString().split(',');
);
selenium xpath
1
what is your expected output? from drop down you can select only one item at times?
– Kajal Kundu
Mar 8 at 21:09
Correct, I am not trying to select an option from the list. I am trying to read the text inside of all option nodes excluding the default. So I am running a protractor helper function that looks like this: getElementsText(locator) let driver = this.helpers.Protractor.browser; return driver.element.all(locator).getAttribute("textContent").then((result) => return result.toString().split(','); ); I need an xpath, that returns all of the option nodes for either select node, without returning the default option node.
– Jason Legako
Mar 8 at 21:13
Thank you for your question I updated the main post with information specifically about what the expected output of the xpath would be.
– Jason Legako
Mar 8 at 21:25
1
Look at this answer for a nice wrapper. Once you have implemented that, use.getOptions()
and ignore the firstOPTION
, e.g. loop 1 to X instead of 0 to X.
– JeffC
Mar 8 at 22:09
add a comment |
Working on an automation test using codeceptjs/selenium, I need to read the text of the nodes of a select drop down without knowing what they will be ahead of time and excluding the greyed out default option (since the app will not function until a choice is made).
<select id="itemname1">
<option class="greydefault">How Many?</option>
<option>6</option>
<option>8</option>
<option>10</option>
<option>12</option>
</select>
<select id="itemname2">
<option class="greydefault">What Type?</option>
<option>a</option>
<option>b</option>
<option>c</option>
<option>d</option>
</select>
Given the above simple dom, question is how to write an xpath that grab all 4 of the option nodes that contain 6 8 10 and 12. And another xpath that returns all 4 of the option nodes a b c and d.
Here are my attempts that don't work for me:
.//option/preceding::option[text()="What Type?"]/following::option[text()="How Many?"]
.//option/following::option[text()="How Many?"]/preceding::option[text()="What Type?"]
.//option/preceding::option[text()="What Type?"] and following::option[text()="How Many?"]
.//option/[preceding::option[text()="What Type?"] and following::option[text()="How Many?"]]
The first 2 attempts returns only the node "How many" for me, and the next attempts are invalid.
The output of the xpath query should return each option node other than the default node.
That xpath is put into a function that reads the texts of the nodes, it looks like this:
getElementsText(locator)
let driver = this.helpers.Protractor.browser;
return driver.element.all(locator).getAttribute("textContent").then((result) =>
return result.toString().split(',');
);
selenium xpath
Working on an automation test using codeceptjs/selenium, I need to read the text of the nodes of a select drop down without knowing what they will be ahead of time and excluding the greyed out default option (since the app will not function until a choice is made).
<select id="itemname1">
<option class="greydefault">How Many?</option>
<option>6</option>
<option>8</option>
<option>10</option>
<option>12</option>
</select>
<select id="itemname2">
<option class="greydefault">What Type?</option>
<option>a</option>
<option>b</option>
<option>c</option>
<option>d</option>
</select>
Given the above simple dom, question is how to write an xpath that grab all 4 of the option nodes that contain 6 8 10 and 12. And another xpath that returns all 4 of the option nodes a b c and d.
Here are my attempts that don't work for me:
.//option/preceding::option[text()="What Type?"]/following::option[text()="How Many?"]
.//option/following::option[text()="How Many?"]/preceding::option[text()="What Type?"]
.//option/preceding::option[text()="What Type?"] and following::option[text()="How Many?"]
.//option/[preceding::option[text()="What Type?"] and following::option[text()="How Many?"]]
The first 2 attempts returns only the node "How many" for me, and the next attempts are invalid.
The output of the xpath query should return each option node other than the default node.
That xpath is put into a function that reads the texts of the nodes, it looks like this:
getElementsText(locator)
let driver = this.helpers.Protractor.browser;
return driver.element.all(locator).getAttribute("textContent").then((result) =>
return result.toString().split(',');
);
selenium xpath
selenium xpath
edited Mar 8 at 21:24
Jason Legako
asked Mar 8 at 20:55
Jason LegakoJason Legako
184
184
1
what is your expected output? from drop down you can select only one item at times?
– Kajal Kundu
Mar 8 at 21:09
Correct, I am not trying to select an option from the list. I am trying to read the text inside of all option nodes excluding the default. So I am running a protractor helper function that looks like this: getElementsText(locator) let driver = this.helpers.Protractor.browser; return driver.element.all(locator).getAttribute("textContent").then((result) => return result.toString().split(','); ); I need an xpath, that returns all of the option nodes for either select node, without returning the default option node.
– Jason Legako
Mar 8 at 21:13
Thank you for your question I updated the main post with information specifically about what the expected output of the xpath would be.
– Jason Legako
Mar 8 at 21:25
1
Look at this answer for a nice wrapper. Once you have implemented that, use.getOptions()
and ignore the firstOPTION
, e.g. loop 1 to X instead of 0 to X.
– JeffC
Mar 8 at 22:09
add a comment |
1
what is your expected output? from drop down you can select only one item at times?
– Kajal Kundu
Mar 8 at 21:09
Correct, I am not trying to select an option from the list. I am trying to read the text inside of all option nodes excluding the default. So I am running a protractor helper function that looks like this: getElementsText(locator) let driver = this.helpers.Protractor.browser; return driver.element.all(locator).getAttribute("textContent").then((result) => return result.toString().split(','); ); I need an xpath, that returns all of the option nodes for either select node, without returning the default option node.
– Jason Legako
Mar 8 at 21:13
Thank you for your question I updated the main post with information specifically about what the expected output of the xpath would be.
– Jason Legako
Mar 8 at 21:25
1
Look at this answer for a nice wrapper. Once you have implemented that, use.getOptions()
and ignore the firstOPTION
, e.g. loop 1 to X instead of 0 to X.
– JeffC
Mar 8 at 22:09
1
1
what is your expected output? from drop down you can select only one item at times?
– Kajal Kundu
Mar 8 at 21:09
what is your expected output? from drop down you can select only one item at times?
– Kajal Kundu
Mar 8 at 21:09
Correct, I am not trying to select an option from the list. I am trying to read the text inside of all option nodes excluding the default. So I am running a protractor helper function that looks like this: getElementsText(locator) let driver = this.helpers.Protractor.browser; return driver.element.all(locator).getAttribute("textContent").then((result) => return result.toString().split(','); ); I need an xpath, that returns all of the option nodes for either select node, without returning the default option node.
– Jason Legako
Mar 8 at 21:13
Correct, I am not trying to select an option from the list. I am trying to read the text inside of all option nodes excluding the default. So I am running a protractor helper function that looks like this: getElementsText(locator) let driver = this.helpers.Protractor.browser; return driver.element.all(locator).getAttribute("textContent").then((result) => return result.toString().split(','); ); I need an xpath, that returns all of the option nodes for either select node, without returning the default option node.
– Jason Legako
Mar 8 at 21:13
Thank you for your question I updated the main post with information specifically about what the expected output of the xpath would be.
– Jason Legako
Mar 8 at 21:25
Thank you for your question I updated the main post with information specifically about what the expected output of the xpath would be.
– Jason Legako
Mar 8 at 21:25
1
1
Look at this answer for a nice wrapper. Once you have implemented that, use
.getOptions()
and ignore the first OPTION
, e.g. loop 1 to X instead of 0 to X.– JeffC
Mar 8 at 22:09
Look at this answer for a nice wrapper. Once you have implemented that, use
.getOptions()
and ignore the first OPTION
, e.g. loop 1 to X instead of 0 to X.– JeffC
Mar 8 at 22:09
add a comment |
3 Answers
3
active
oldest
votes
Get all option
elements based on the default one's text (displayed value) in this select
:
//select[option[text()="How Many?"]]/option[not(@class="greydefault")]
Get all based on the the parent select
's id:
//select[@id="itemname2"]/option[not(@class="greydefault")]
In both cases you first find the select
element - in the first, the one that has a child option
with that text; in the 2nd - the one with that id, and then get all its children (direct descendants) that do not have that class
value.
add a comment |
Here is the css that will fetch all the options except the default.
First List:
select#itemname1 option:not(:first-child)
Second List:
select#itemname2 option:not(:first-child)
add a comment |
Extremely confusingly to me, this is working to grab the options in the second list excluding the default, but when I read this I assume it should be grabbing the first set of options excluding the default.
.//option[following::option[text()="How Many?"] and preceding::option[text()="What Type?"]]
1
Nope, not really -following
andpreceding
work down/up the nodes tree, while theseoption
tags are in paralel branches. If that sounds confusing, imagine a pyramid structure - a boss/employee structure. Up the tree will be your boss, then her boss and so on, down - your employee, then her employee etc. A parallel branch is another department - which you don't have anything in common with; yours and the other one will have a common boss somewhere up the tree.
– Todor Minakov
Mar 9 at 4:34
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%2f55070857%2fxpath-selenium-how-do-i-grab-all-of-the-options-in-a-select-excluding-the%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Get all option
elements based on the default one's text (displayed value) in this select
:
//select[option[text()="How Many?"]]/option[not(@class="greydefault")]
Get all based on the the parent select
's id:
//select[@id="itemname2"]/option[not(@class="greydefault")]
In both cases you first find the select
element - in the first, the one that has a child option
with that text; in the 2nd - the one with that id, and then get all its children (direct descendants) that do not have that class
value.
add a comment |
Get all option
elements based on the default one's text (displayed value) in this select
:
//select[option[text()="How Many?"]]/option[not(@class="greydefault")]
Get all based on the the parent select
's id:
//select[@id="itemname2"]/option[not(@class="greydefault")]
In both cases you first find the select
element - in the first, the one that has a child option
with that text; in the 2nd - the one with that id, and then get all its children (direct descendants) that do not have that class
value.
add a comment |
Get all option
elements based on the default one's text (displayed value) in this select
:
//select[option[text()="How Many?"]]/option[not(@class="greydefault")]
Get all based on the the parent select
's id:
//select[@id="itemname2"]/option[not(@class="greydefault")]
In both cases you first find the select
element - in the first, the one that has a child option
with that text; in the 2nd - the one with that id, and then get all its children (direct descendants) that do not have that class
value.
Get all option
elements based on the default one's text (displayed value) in this select
:
//select[option[text()="How Many?"]]/option[not(@class="greydefault")]
Get all based on the the parent select
's id:
//select[@id="itemname2"]/option[not(@class="greydefault")]
In both cases you first find the select
element - in the first, the one that has a child option
with that text; in the 2nd - the one with that id, and then get all its children (direct descendants) that do not have that class
value.
answered Mar 9 at 4:26
Todor MinakovTodor Minakov
7,68212739
7,68212739
add a comment |
add a comment |
Here is the css that will fetch all the options except the default.
First List:
select#itemname1 option:not(:first-child)
Second List:
select#itemname2 option:not(:first-child)
add a comment |
Here is the css that will fetch all the options except the default.
First List:
select#itemname1 option:not(:first-child)
Second List:
select#itemname2 option:not(:first-child)
add a comment |
Here is the css that will fetch all the options except the default.
First List:
select#itemname1 option:not(:first-child)
Second List:
select#itemname2 option:not(:first-child)
Here is the css that will fetch all the options except the default.
First List:
select#itemname1 option:not(:first-child)
Second List:
select#itemname2 option:not(:first-child)
edited Mar 8 at 22:14
answered Mar 8 at 22:05
supputurisupputuri
1,0161612
1,0161612
add a comment |
add a comment |
Extremely confusingly to me, this is working to grab the options in the second list excluding the default, but when I read this I assume it should be grabbing the first set of options excluding the default.
.//option[following::option[text()="How Many?"] and preceding::option[text()="What Type?"]]
1
Nope, not really -following
andpreceding
work down/up the nodes tree, while theseoption
tags are in paralel branches. If that sounds confusing, imagine a pyramid structure - a boss/employee structure. Up the tree will be your boss, then her boss and so on, down - your employee, then her employee etc. A parallel branch is another department - which you don't have anything in common with; yours and the other one will have a common boss somewhere up the tree.
– Todor Minakov
Mar 9 at 4:34
add a comment |
Extremely confusingly to me, this is working to grab the options in the second list excluding the default, but when I read this I assume it should be grabbing the first set of options excluding the default.
.//option[following::option[text()="How Many?"] and preceding::option[text()="What Type?"]]
1
Nope, not really -following
andpreceding
work down/up the nodes tree, while theseoption
tags are in paralel branches. If that sounds confusing, imagine a pyramid structure - a boss/employee structure. Up the tree will be your boss, then her boss and so on, down - your employee, then her employee etc. A parallel branch is another department - which you don't have anything in common with; yours and the other one will have a common boss somewhere up the tree.
– Todor Minakov
Mar 9 at 4:34
add a comment |
Extremely confusingly to me, this is working to grab the options in the second list excluding the default, but when I read this I assume it should be grabbing the first set of options excluding the default.
.//option[following::option[text()="How Many?"] and preceding::option[text()="What Type?"]]
Extremely confusingly to me, this is working to grab the options in the second list excluding the default, but when I read this I assume it should be grabbing the first set of options excluding the default.
.//option[following::option[text()="How Many?"] and preceding::option[text()="What Type?"]]
answered Mar 8 at 21:35
Jason LegakoJason Legako
184
184
1
Nope, not really -following
andpreceding
work down/up the nodes tree, while theseoption
tags are in paralel branches. If that sounds confusing, imagine a pyramid structure - a boss/employee structure. Up the tree will be your boss, then her boss and so on, down - your employee, then her employee etc. A parallel branch is another department - which you don't have anything in common with; yours and the other one will have a common boss somewhere up the tree.
– Todor Minakov
Mar 9 at 4:34
add a comment |
1
Nope, not really -following
andpreceding
work down/up the nodes tree, while theseoption
tags are in paralel branches. If that sounds confusing, imagine a pyramid structure - a boss/employee structure. Up the tree will be your boss, then her boss and so on, down - your employee, then her employee etc. A parallel branch is another department - which you don't have anything in common with; yours and the other one will have a common boss somewhere up the tree.
– Todor Minakov
Mar 9 at 4:34
1
1
Nope, not really -
following
and preceding
work down/up the nodes tree, while these option
tags are in paralel branches. If that sounds confusing, imagine a pyramid structure - a boss/employee structure. Up the tree will be your boss, then her boss and so on, down - your employee, then her employee etc. A parallel branch is another department - which you don't have anything in common with; yours and the other one will have a common boss somewhere up the tree.– Todor Minakov
Mar 9 at 4:34
Nope, not really -
following
and preceding
work down/up the nodes tree, while these option
tags are in paralel branches. If that sounds confusing, imagine a pyramid structure - a boss/employee structure. Up the tree will be your boss, then her boss and so on, down - your employee, then her employee etc. A parallel branch is another department - which you don't have anything in common with; yours and the other one will have a common boss somewhere up the tree.– Todor Minakov
Mar 9 at 4:34
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.
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%2f55070857%2fxpath-selenium-how-do-i-grab-all-of-the-options-in-a-select-excluding-the%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
1
what is your expected output? from drop down you can select only one item at times?
– Kajal Kundu
Mar 8 at 21:09
Correct, I am not trying to select an option from the list. I am trying to read the text inside of all option nodes excluding the default. So I am running a protractor helper function that looks like this: getElementsText(locator) let driver = this.helpers.Protractor.browser; return driver.element.all(locator).getAttribute("textContent").then((result) => return result.toString().split(','); ); I need an xpath, that returns all of the option nodes for either select node, without returning the default option node.
– Jason Legako
Mar 8 at 21:13
Thank you for your question I updated the main post with information specifically about what the expected output of the xpath would be.
– Jason Legako
Mar 8 at 21:25
1
Look at this answer for a nice wrapper. Once you have implemented that, use
.getOptions()
and ignore the firstOPTION
, e.g. loop 1 to X instead of 0 to X.– JeffC
Mar 8 at 22:09