xpath link two attributes











up vote
0
down vote

favorite












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.



enter image description here



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.










share|improve this question









New contributor




Devin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • pls take the effort to make a reproduceable sample, also have a look into the Q&A Guidelines
    – LuckyLikey
    20 hours ago










  • Possible duplicate of Selenium checkbox attribute "checked"
    – JeffC
    20 hours ago















up vote
0
down vote

favorite












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.



enter image description here



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.










share|improve this question









New contributor




Devin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • pls take the effort to make a reproduceable sample, also have a look into the Q&A Guidelines
    – LuckyLikey
    20 hours ago










  • Possible duplicate of Selenium checkbox attribute "checked"
    – JeffC
    20 hours ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











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.



enter image description here



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.










share|improve this question









New contributor




Devin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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.



enter image description here



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






share|improve this question









New contributor




Devin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Devin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 20 hours ago









Andersson

34.1k103063




34.1k103063






New contributor




Devin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 21 hours ago









Devin

31




31




New contributor




Devin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Devin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Devin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • pls take the effort to make a reproduceable sample, also have a look into the Q&A Guidelines
    – LuckyLikey
    20 hours ago










  • Possible duplicate of Selenium checkbox attribute "checked"
    – JeffC
    20 hours ago


















  • pls take the effort to make a reproduceable sample, also have a look into the Q&A Guidelines
    – LuckyLikey
    20 hours ago










  • Possible duplicate of Selenium checkbox attribute "checked"
    – JeffC
    20 hours ago
















pls take the effort to make a reproduceable sample, also have a look into the Q&A Guidelines
– LuckyLikey
20 hours ago




pls take the effort to make a reproduceable sample, also have a look into the Q&A Guidelines
– LuckyLikey
20 hours ago












Possible duplicate of Selenium checkbox attribute "checked"
– JeffC
20 hours ago




Possible duplicate of Selenium checkbox attribute "checked"
– JeffC
20 hours ago












2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










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






share|improve this answer





















  • Yes! This! Thank you so much!
    – Devin
    20 hours ago










  • You really should be using .Selected or .isSelected(), etc. and not trying to do this with locators. See the dup I linked.
    – JeffC
    20 hours ago




















up vote
-1
down vote













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.






share|improve this answer





















  • 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
    20 hours ago













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',
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
});


}
});






Devin is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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
































2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










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






share|improve this answer





















  • Yes! This! Thank you so much!
    – Devin
    20 hours ago










  • You really should be using .Selected or .isSelected(), etc. and not trying to do this with locators. See the dup I linked.
    – JeffC
    20 hours ago

















up vote
0
down vote



accepted










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






share|improve this answer





















  • Yes! This! Thank you so much!
    – Devin
    20 hours ago










  • You really should be using .Selected or .isSelected(), etc. and not trying to do this with locators. See the dup I linked.
    – JeffC
    20 hours ago















up vote
0
down vote



accepted







up vote
0
down vote



accepted






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






share|improve this answer












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







share|improve this answer












share|improve this answer



share|improve this answer










answered 20 hours ago









Andersson

34.1k103063




34.1k103063












  • Yes! This! Thank you so much!
    – Devin
    20 hours ago










  • You really should be using .Selected or .isSelected(), etc. and not trying to do this with locators. See the dup I linked.
    – JeffC
    20 hours ago




















  • Yes! This! Thank you so much!
    – Devin
    20 hours ago










  • You really should be using .Selected or .isSelected(), etc. and not trying to do this with locators. See the dup I linked.
    – JeffC
    20 hours ago


















Yes! This! Thank you so much!
– Devin
20 hours ago




Yes! This! Thank you so much!
– Devin
20 hours ago












You really should be using .Selected or .isSelected(), etc. and not trying to do this with locators. See the dup I linked.
– JeffC
20 hours ago






You really should be using .Selected or .isSelected(), etc. and not trying to do this with locators. See the dup I linked.
– JeffC
20 hours ago














up vote
-1
down vote













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.






share|improve this answer





















  • 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
    20 hours ago

















up vote
-1
down vote













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.






share|improve this answer





















  • 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
    20 hours ago















up vote
-1
down vote










up vote
-1
down vote









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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










answered 20 hours ago









IPolnik

245




245












  • 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
    20 hours ago




















  • 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
    20 hours ago


















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
20 hours ago






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
20 hours ago












Devin is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Devin is a new contributor. Be nice, and check out our Code of Conduct.













Devin is a new contributor. Be nice, and check out our Code of Conduct.












Devin is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














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




















































































Popular posts from this blog

How to send String Array data to Server using php in android

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Is anime1.com a legal site for watching anime?