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.

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
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.
add a comment |
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.

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
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
add a comment |
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.

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
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.

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
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.
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
add a comment |
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
add a comment |
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
Yes! This! Thank you so much!
– Devin
20 hours ago
You really should be using.Selectedor.isSelected(), etc. and not trying to do this with locators. See the dup I linked.
– JeffC
20 hours ago
add a comment |
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.
You're trying to pass XPath (with invalid syntax) toBy.namemethod. That definitely won't work. Also how do you know that OP uses Java?
– Andersson
20 hours ago
add a comment |
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
Yes! This! Thank you so much!
– Devin
20 hours ago
You really should be using.Selectedor.isSelected(), etc. and not trying to do this with locators. See the dup I linked.
– JeffC
20 hours ago
add a comment |
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
Yes! This! Thank you so much!
– Devin
20 hours ago
You really should be using.Selectedor.isSelected(), etc. and not trying to do this with locators. See the dup I linked.
– JeffC
20 hours ago
add a comment |
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
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 20 hours ago
Andersson
34.1k103063
34.1k103063
Yes! This! Thank you so much!
– Devin
20 hours ago
You really should be using.Selectedor.isSelected(), etc. and not trying to do this with locators. See the dup I linked.
– JeffC
20 hours ago
add a comment |
Yes! This! Thank you so much!
– Devin
20 hours ago
You really should be using.Selectedor.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
add a comment |
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.
You're trying to pass XPath (with invalid syntax) toBy.namemethod. That definitely won't work. Also how do you know that OP uses Java?
– Andersson
20 hours ago
add a comment |
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.
You're trying to pass XPath (with invalid syntax) toBy.namemethod. That definitely won't work. Also how do you know that OP uses Java?
– Andersson
20 hours ago
add a comment |
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.
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 20 hours ago
IPolnik
245
245
You're trying to pass XPath (with invalid syntax) toBy.namemethod. That definitely won't work. Also how do you know that OP uses Java?
– Andersson
20 hours ago
add a comment |
You're trying to pass XPath (with invalid syntax) toBy.namemethod. 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
add a comment |
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.
Devin is a new contributor. Be nice, and check out our Code of Conduct.
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
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
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
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
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
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