xpath link two attributes
So I'm trying to automate testing with selenium, and need to see if a check box is checked for a specific user. The page looks like this.
The first user's checkbox is not checked, and the second is. So, when checked there's a checkbox="checked" attribute that isn't there when not checked. I'm not sure how I would format it so that I'm able to specifically look at the box of the one that I'm looking for. I tried (//input[contains(@name='user_5166855' and @checked='checked')])
but it didn't seem to work.
xml selenium xpath
add a comment |
So I'm trying to automate testing with selenium, and need to see if a check box is checked for a specific user. The page looks like this.
The first user's checkbox is not checked, and the second is. So, when checked there's a checkbox="checked" attribute that isn't there when not checked. I'm not sure how I would format it so that I'm able to specifically look at the box of the one that I'm looking for. I tried (//input[contains(@name='user_5166855' and @checked='checked')])
but it didn't seem to work.
xml selenium xpath
pls take the effort to make a reproduceable sample, also have a look into the Q&A Guidelines
– LuckyLikey
Nov 12 at 16:06
Possible duplicate of Selenium checkbox attribute "checked"
– JeffC
Nov 12 at 16:54
add a comment |
So I'm trying to automate testing with selenium, and need to see if a check box is checked for a specific user. The page looks like this.
The first user's checkbox is not checked, and the second is. So, when checked there's a checkbox="checked" attribute that isn't there when not checked. I'm not sure how I would format it so that I'm able to specifically look at the box of the one that I'm looking for. I tried (//input[contains(@name='user_5166855' and @checked='checked')])
but it didn't seem to work.
xml selenium xpath
So I'm trying to automate testing with selenium, and need to see if a check box is checked for a specific user. The page looks like this.
The first user's checkbox is not checked, and the second is. So, when checked there's a checkbox="checked" attribute that isn't there when not checked. I'm not sure how I would format it so that I'm able to specifically look at the box of the one that I'm looking for. I tried (//input[contains(@name='user_5166855' and @checked='checked')])
but it didn't seem to work.
xml selenium xpath
xml selenium xpath
edited Nov 12 at 16:07
Andersson
36.8k103266
36.8k103266
asked Nov 12 at 15:51
Devin
31
31
pls take the effort to make a reproduceable sample, also have a look into the Q&A Guidelines
– LuckyLikey
Nov 12 at 16:06
Possible duplicate of Selenium checkbox attribute "checked"
– JeffC
Nov 12 at 16:54
add a comment |
pls take the effort to make a reproduceable sample, also have a look into the Q&A Guidelines
– LuckyLikey
Nov 12 at 16:06
Possible duplicate of Selenium checkbox attribute "checked"
– JeffC
Nov 12 at 16:54
pls take the effort to make a reproduceable sample, also have a look into the Q&A Guidelines
– LuckyLikey
Nov 12 at 16:06
pls take the effort to make a reproduceable sample, also have a look into the Q&A Guidelines
– LuckyLikey
Nov 12 at 16:06
Possible duplicate of Selenium checkbox attribute "checked"
– JeffC
Nov 12 at 16:54
Possible duplicate of Selenium checkbox attribute "checked"
– JeffC
Nov 12 at 16:54
add a comment |
2 Answers
2
active
oldest
votes
Try below XPath to select
checked one
//input[@name="user_5166855" and @checked]
unchecked
//input[@name="user_5166855" and not(@checked)]
Note that checked
is boolean attribute, so there is no need to verify the value of attribute - verifying existence should be enough
Yes! This! Thank you so much!
– Devin
Nov 12 at 16:54
You really should be using.Selected
or.isSelected()
, etc. and not trying to do this with locators. See the dup I linked.
– JeffC
Nov 12 at 16:54
add a comment |
So, you already have an Xpath for your second user all u need to do is:
public boolean IsCheckBoxChecked()
{
try
{
driver.findElement(By.name("//input[contains(@name='user_5166855' and @checked='checked')]")).getAttribute("checked")
}
catch
{
false
}
}
So what u r doing here u find your element, in try block then your test is going to pass, if there is no such attribute for element(checkbox unchecked), then its will return false and assertion failed.
You're trying to pass XPath (with invalid syntax) toBy.name
method. That definitely won't work. Also how do you know that OP uses Java?
– Andersson
Nov 12 at 16:23
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%2f53265670%2fxpath-link-two-attributes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try below XPath to select
checked one
//input[@name="user_5166855" and @checked]
unchecked
//input[@name="user_5166855" and not(@checked)]
Note that checked
is boolean attribute, so there is no need to verify the value of attribute - verifying existence should be enough
Yes! This! Thank you so much!
– Devin
Nov 12 at 16:54
You really should be using.Selected
or.isSelected()
, etc. and not trying to do this with locators. See the dup I linked.
– JeffC
Nov 12 at 16:54
add a comment |
Try below XPath to select
checked one
//input[@name="user_5166855" and @checked]
unchecked
//input[@name="user_5166855" and not(@checked)]
Note that checked
is boolean attribute, so there is no need to verify the value of attribute - verifying existence should be enough
Yes! This! Thank you so much!
– Devin
Nov 12 at 16:54
You really should be using.Selected
or.isSelected()
, etc. and not trying to do this with locators. See the dup I linked.
– JeffC
Nov 12 at 16:54
add a comment |
Try below XPath to select
checked one
//input[@name="user_5166855" and @checked]
unchecked
//input[@name="user_5166855" and not(@checked)]
Note that checked
is boolean attribute, so there is no need to verify the value of attribute - verifying existence should be enough
Try below XPath to select
checked one
//input[@name="user_5166855" and @checked]
unchecked
//input[@name="user_5166855" and not(@checked)]
Note that checked
is boolean attribute, so there is no need to verify the value of attribute - verifying existence should be enough
answered Nov 12 at 16:04
Andersson
36.8k103266
36.8k103266
Yes! This! Thank you so much!
– Devin
Nov 12 at 16:54
You really should be using.Selected
or.isSelected()
, etc. and not trying to do this with locators. See the dup I linked.
– JeffC
Nov 12 at 16:54
add a comment |
Yes! This! Thank you so much!
– Devin
Nov 12 at 16:54
You really should be using.Selected
or.isSelected()
, etc. and not trying to do this with locators. See the dup I linked.
– JeffC
Nov 12 at 16:54
Yes! This! Thank you so much!
– Devin
Nov 12 at 16:54
Yes! This! Thank you so much!
– Devin
Nov 12 at 16:54
You really should be using
.Selected
or .isSelected()
, etc. and not trying to do this with locators. See the dup I linked.– JeffC
Nov 12 at 16:54
You really should be using
.Selected
or .isSelected()
, etc. and not trying to do this with locators. See the dup I linked.– JeffC
Nov 12 at 16:54
add a comment |
So, you already have an Xpath for your second user all u need to do is:
public boolean IsCheckBoxChecked()
{
try
{
driver.findElement(By.name("//input[contains(@name='user_5166855' and @checked='checked')]")).getAttribute("checked")
}
catch
{
false
}
}
So what u r doing here u find your element, in try block then your test is going to pass, if there is no such attribute for element(checkbox unchecked), then its will return false and assertion failed.
You're trying to pass XPath (with invalid syntax) toBy.name
method. That definitely won't work. Also how do you know that OP uses Java?
– Andersson
Nov 12 at 16:23
add a comment |
So, you already have an Xpath for your second user all u need to do is:
public boolean IsCheckBoxChecked()
{
try
{
driver.findElement(By.name("//input[contains(@name='user_5166855' and @checked='checked')]")).getAttribute("checked")
}
catch
{
false
}
}
So what u r doing here u find your element, in try block then your test is going to pass, if there is no such attribute for element(checkbox unchecked), then its will return false and assertion failed.
You're trying to pass XPath (with invalid syntax) toBy.name
method. That definitely won't work. Also how do you know that OP uses Java?
– Andersson
Nov 12 at 16:23
add a comment |
So, you already have an Xpath for your second user all u need to do is:
public boolean IsCheckBoxChecked()
{
try
{
driver.findElement(By.name("//input[contains(@name='user_5166855' and @checked='checked')]")).getAttribute("checked")
}
catch
{
false
}
}
So what u r doing here u find your element, in try block then your test is going to pass, if there is no such attribute for element(checkbox unchecked), then its will return false and assertion failed.
So, you already have an Xpath for your second user all u need to do is:
public boolean IsCheckBoxChecked()
{
try
{
driver.findElement(By.name("//input[contains(@name='user_5166855' and @checked='checked')]")).getAttribute("checked")
}
catch
{
false
}
}
So what u r doing here u find your element, in try block then your test is going to pass, if there is no such attribute for element(checkbox unchecked), then its will return false and assertion failed.
answered Nov 12 at 16:15
IPolnik
245
245
You're trying to pass XPath (with invalid syntax) toBy.name
method. That definitely won't work. Also how do you know that OP uses Java?
– Andersson
Nov 12 at 16:23
add a comment |
You're trying to pass XPath (with invalid syntax) toBy.name
method. That definitely won't work. Also how do you know that OP uses Java?
– Andersson
Nov 12 at 16:23
You're trying to pass XPath (with invalid syntax) to
By.name
method. That definitely won't work. Also how do you know that OP uses Java?– Andersson
Nov 12 at 16:23
You're trying to pass XPath (with invalid syntax) to
By.name
method. That definitely won't work. Also how do you know that OP uses Java?– Andersson
Nov 12 at 16:23
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%2f53265670%2fxpath-link-two-attributes%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
pls take the effort to make a reproduceable sample, also have a look into the Q&A Guidelines
– LuckyLikey
Nov 12 at 16:06
Possible duplicate of Selenium checkbox attribute "checked"
– JeffC
Nov 12 at 16:54