C# Selenium xpath cannot find the inner div node
up vote
0
down vote
favorite
I tried to access the second inner div node. Here is the structure:
<div class = "bPageBlock brandSecondaryBrd bDetailBlock secondaryPalette" id="ep">
<div class ="pbHeader"></div>
<div class ="pbBody"></div>
Through ChroPath add on, with the below xpath it can match the
"pbHeader" class
"html/body/div[4]/div[1]"
While trying with the same logic to access the pbBody class it is not pointed to that div node.
"html/body/div[4]/div[2]"
I have to access the element inside pbBody div class.
c# selenium selenium-webdriver xpath
add a comment |
up vote
0
down vote
favorite
I tried to access the second inner div node. Here is the structure:
<div class = "bPageBlock brandSecondaryBrd bDetailBlock secondaryPalette" id="ep">
<div class ="pbHeader"></div>
<div class ="pbBody"></div>
Through ChroPath add on, with the below xpath it can match the
"pbHeader" class
"html/body/div[4]/div[1]"
While trying with the same logic to access the pbBody class it is not pointed to that div node.
"html/body/div[4]/div[2]"
I have to access the element inside pbBody div class.
c# selenium selenium-webdriver xpath
2
could you share entire snippet of HTML.
– Ashok kumar Ganesan
Nov 8 at 16:48
The snippet I provided is deep in html - is there a fast way to grab the entire structure?
– Crez43
Nov 8 at 17:40
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I tried to access the second inner div node. Here is the structure:
<div class = "bPageBlock brandSecondaryBrd bDetailBlock secondaryPalette" id="ep">
<div class ="pbHeader"></div>
<div class ="pbBody"></div>
Through ChroPath add on, with the below xpath it can match the
"pbHeader" class
"html/body/div[4]/div[1]"
While trying with the same logic to access the pbBody class it is not pointed to that div node.
"html/body/div[4]/div[2]"
I have to access the element inside pbBody div class.
c# selenium selenium-webdriver xpath
I tried to access the second inner div node. Here is the structure:
<div class = "bPageBlock brandSecondaryBrd bDetailBlock secondaryPalette" id="ep">
<div class ="pbHeader"></div>
<div class ="pbBody"></div>
Through ChroPath add on, with the below xpath it can match the
"pbHeader" class
"html/body/div[4]/div[1]"
While trying with the same logic to access the pbBody class it is not pointed to that div node.
"html/body/div[4]/div[2]"
I have to access the element inside pbBody div class.
c# selenium selenium-webdriver xpath
c# selenium selenium-webdriver xpath
edited Nov 8 at 17:37
DebanjanB
35.4k73271
35.4k73271
asked Nov 8 at 16:46
Crez43
1
1
2
could you share entire snippet of HTML.
– Ashok kumar Ganesan
Nov 8 at 16:48
The snippet I provided is deep in html - is there a fast way to grab the entire structure?
– Crez43
Nov 8 at 17:40
add a comment |
2
could you share entire snippet of HTML.
– Ashok kumar Ganesan
Nov 8 at 16:48
The snippet I provided is deep in html - is there a fast way to grab the entire structure?
– Crez43
Nov 8 at 17:40
2
2
could you share entire snippet of HTML.
– Ashok kumar Ganesan
Nov 8 at 16:48
could you share entire snippet of HTML.
– Ashok kumar Ganesan
Nov 8 at 16:48
The snippet I provided is deep in html - is there a fast way to grab the entire structure?
– Crez43
Nov 8 at 17:40
The snippet I provided is deep in html - is there a fast way to grab the entire structure?
– Crez43
Nov 8 at 17:40
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
For something simple like this, you should use CSS selectors.
#ep > div.pbHeader
#ep > div.pbBody
If you've omitted some HTML in your question, you might need to remove the >
indicating child, e.g.
#ep div.pbHeader
#ep div.pbBody
But... if you must use XPath, you can use the below
//[@id='ep']/div[@class='pbBody']
1
Generally, if you're trying to find a bug in your code, having someone on the sidelines telling you to rewrite the thing in a different programming language is just an unwanted distraction. Switching technologies every time you hit a minor obstacle is not a good way to make progress.
– Michael Kay
Nov 8 at 20:29
@MichaelKay Selenium has many locator types available. Switching from XPath to CSS selectors is not a different programming language nor a different technology. There are a number of reasons not to use XPath but I won't go into all that here. You can google, if you are interested.
– JeffC
Nov 8 at 20:36
@MichaelKay ...but I take your point. I've added an XPath example, if you want to provide some feedback since you are an actual XPath expert. :)
– JeffC
Nov 8 at 20:40
1
I'm not saying that using CSS rather than XPath is the wrong approach (on the contrary, CSS was designed for HTML and XPath wasn't); just that I don't think you should make decisions like that in response to this kind of problem. (I can't help debug the XPath here because we don't know enough about the HTML.)
– Michael Kay
Nov 8 at 22:09
1
Certainly agree with you that people trying to write XPath expressions with no attempt to learn the syntax or semantics of the language except by looking at examples is a major plague.
– Michael Kay
Nov 9 at 8:02
|
show 1 more comment
up vote
-1
down vote
Instead of absolute xpath you should use relative xpath as follows:
driver.FindElement(By.XPath("//div[@class='bPageBlock brandSecondaryBrd bDetailBlock secondaryPalette' and @id='ep']//div[@class='pbBody']"));
2
checking classes when your element relies on@id='ep'
is redundant. Also you are making a lot of assumptions here: what if classes are not always int he same order? what ifep
is not static id?
– Kiril S.
Nov 8 at 17:42
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
For something simple like this, you should use CSS selectors.
#ep > div.pbHeader
#ep > div.pbBody
If you've omitted some HTML in your question, you might need to remove the >
indicating child, e.g.
#ep div.pbHeader
#ep div.pbBody
But... if you must use XPath, you can use the below
//[@id='ep']/div[@class='pbBody']
1
Generally, if you're trying to find a bug in your code, having someone on the sidelines telling you to rewrite the thing in a different programming language is just an unwanted distraction. Switching technologies every time you hit a minor obstacle is not a good way to make progress.
– Michael Kay
Nov 8 at 20:29
@MichaelKay Selenium has many locator types available. Switching from XPath to CSS selectors is not a different programming language nor a different technology. There are a number of reasons not to use XPath but I won't go into all that here. You can google, if you are interested.
– JeffC
Nov 8 at 20:36
@MichaelKay ...but I take your point. I've added an XPath example, if you want to provide some feedback since you are an actual XPath expert. :)
– JeffC
Nov 8 at 20:40
1
I'm not saying that using CSS rather than XPath is the wrong approach (on the contrary, CSS was designed for HTML and XPath wasn't); just that I don't think you should make decisions like that in response to this kind of problem. (I can't help debug the XPath here because we don't know enough about the HTML.)
– Michael Kay
Nov 8 at 22:09
1
Certainly agree with you that people trying to write XPath expressions with no attempt to learn the syntax or semantics of the language except by looking at examples is a major plague.
– Michael Kay
Nov 9 at 8:02
|
show 1 more comment
up vote
0
down vote
For something simple like this, you should use CSS selectors.
#ep > div.pbHeader
#ep > div.pbBody
If you've omitted some HTML in your question, you might need to remove the >
indicating child, e.g.
#ep div.pbHeader
#ep div.pbBody
But... if you must use XPath, you can use the below
//[@id='ep']/div[@class='pbBody']
1
Generally, if you're trying to find a bug in your code, having someone on the sidelines telling you to rewrite the thing in a different programming language is just an unwanted distraction. Switching technologies every time you hit a minor obstacle is not a good way to make progress.
– Michael Kay
Nov 8 at 20:29
@MichaelKay Selenium has many locator types available. Switching from XPath to CSS selectors is not a different programming language nor a different technology. There are a number of reasons not to use XPath but I won't go into all that here. You can google, if you are interested.
– JeffC
Nov 8 at 20:36
@MichaelKay ...but I take your point. I've added an XPath example, if you want to provide some feedback since you are an actual XPath expert. :)
– JeffC
Nov 8 at 20:40
1
I'm not saying that using CSS rather than XPath is the wrong approach (on the contrary, CSS was designed for HTML and XPath wasn't); just that I don't think you should make decisions like that in response to this kind of problem. (I can't help debug the XPath here because we don't know enough about the HTML.)
– Michael Kay
Nov 8 at 22:09
1
Certainly agree with you that people trying to write XPath expressions with no attempt to learn the syntax or semantics of the language except by looking at examples is a major plague.
– Michael Kay
Nov 9 at 8:02
|
show 1 more comment
up vote
0
down vote
up vote
0
down vote
For something simple like this, you should use CSS selectors.
#ep > div.pbHeader
#ep > div.pbBody
If you've omitted some HTML in your question, you might need to remove the >
indicating child, e.g.
#ep div.pbHeader
#ep div.pbBody
But... if you must use XPath, you can use the below
//[@id='ep']/div[@class='pbBody']
For something simple like this, you should use CSS selectors.
#ep > div.pbHeader
#ep > div.pbBody
If you've omitted some HTML in your question, you might need to remove the >
indicating child, e.g.
#ep div.pbHeader
#ep div.pbBody
But... if you must use XPath, you can use the below
//[@id='ep']/div[@class='pbBody']
edited Nov 8 at 20:38
answered Nov 8 at 19:58
JeffC
11.7k41435
11.7k41435
1
Generally, if you're trying to find a bug in your code, having someone on the sidelines telling you to rewrite the thing in a different programming language is just an unwanted distraction. Switching technologies every time you hit a minor obstacle is not a good way to make progress.
– Michael Kay
Nov 8 at 20:29
@MichaelKay Selenium has many locator types available. Switching from XPath to CSS selectors is not a different programming language nor a different technology. There are a number of reasons not to use XPath but I won't go into all that here. You can google, if you are interested.
– JeffC
Nov 8 at 20:36
@MichaelKay ...but I take your point. I've added an XPath example, if you want to provide some feedback since you are an actual XPath expert. :)
– JeffC
Nov 8 at 20:40
1
I'm not saying that using CSS rather than XPath is the wrong approach (on the contrary, CSS was designed for HTML and XPath wasn't); just that I don't think you should make decisions like that in response to this kind of problem. (I can't help debug the XPath here because we don't know enough about the HTML.)
– Michael Kay
Nov 8 at 22:09
1
Certainly agree with you that people trying to write XPath expressions with no attempt to learn the syntax or semantics of the language except by looking at examples is a major plague.
– Michael Kay
Nov 9 at 8:02
|
show 1 more comment
1
Generally, if you're trying to find a bug in your code, having someone on the sidelines telling you to rewrite the thing in a different programming language is just an unwanted distraction. Switching technologies every time you hit a minor obstacle is not a good way to make progress.
– Michael Kay
Nov 8 at 20:29
@MichaelKay Selenium has many locator types available. Switching from XPath to CSS selectors is not a different programming language nor a different technology. There are a number of reasons not to use XPath but I won't go into all that here. You can google, if you are interested.
– JeffC
Nov 8 at 20:36
@MichaelKay ...but I take your point. I've added an XPath example, if you want to provide some feedback since you are an actual XPath expert. :)
– JeffC
Nov 8 at 20:40
1
I'm not saying that using CSS rather than XPath is the wrong approach (on the contrary, CSS was designed for HTML and XPath wasn't); just that I don't think you should make decisions like that in response to this kind of problem. (I can't help debug the XPath here because we don't know enough about the HTML.)
– Michael Kay
Nov 8 at 22:09
1
Certainly agree with you that people trying to write XPath expressions with no attempt to learn the syntax or semantics of the language except by looking at examples is a major plague.
– Michael Kay
Nov 9 at 8:02
1
1
Generally, if you're trying to find a bug in your code, having someone on the sidelines telling you to rewrite the thing in a different programming language is just an unwanted distraction. Switching technologies every time you hit a minor obstacle is not a good way to make progress.
– Michael Kay
Nov 8 at 20:29
Generally, if you're trying to find a bug in your code, having someone on the sidelines telling you to rewrite the thing in a different programming language is just an unwanted distraction. Switching technologies every time you hit a minor obstacle is not a good way to make progress.
– Michael Kay
Nov 8 at 20:29
@MichaelKay Selenium has many locator types available. Switching from XPath to CSS selectors is not a different programming language nor a different technology. There are a number of reasons not to use XPath but I won't go into all that here. You can google, if you are interested.
– JeffC
Nov 8 at 20:36
@MichaelKay Selenium has many locator types available. Switching from XPath to CSS selectors is not a different programming language nor a different technology. There are a number of reasons not to use XPath but I won't go into all that here. You can google, if you are interested.
– JeffC
Nov 8 at 20:36
@MichaelKay ...but I take your point. I've added an XPath example, if you want to provide some feedback since you are an actual XPath expert. :)
– JeffC
Nov 8 at 20:40
@MichaelKay ...but I take your point. I've added an XPath example, if you want to provide some feedback since you are an actual XPath expert. :)
– JeffC
Nov 8 at 20:40
1
1
I'm not saying that using CSS rather than XPath is the wrong approach (on the contrary, CSS was designed for HTML and XPath wasn't); just that I don't think you should make decisions like that in response to this kind of problem. (I can't help debug the XPath here because we don't know enough about the HTML.)
– Michael Kay
Nov 8 at 22:09
I'm not saying that using CSS rather than XPath is the wrong approach (on the contrary, CSS was designed for HTML and XPath wasn't); just that I don't think you should make decisions like that in response to this kind of problem. (I can't help debug the XPath here because we don't know enough about the HTML.)
– Michael Kay
Nov 8 at 22:09
1
1
Certainly agree with you that people trying to write XPath expressions with no attempt to learn the syntax or semantics of the language except by looking at examples is a major plague.
– Michael Kay
Nov 9 at 8:02
Certainly agree with you that people trying to write XPath expressions with no attempt to learn the syntax or semantics of the language except by looking at examples is a major plague.
– Michael Kay
Nov 9 at 8:02
|
show 1 more comment
up vote
-1
down vote
Instead of absolute xpath you should use relative xpath as follows:
driver.FindElement(By.XPath("//div[@class='bPageBlock brandSecondaryBrd bDetailBlock secondaryPalette' and @id='ep']//div[@class='pbBody']"));
2
checking classes when your element relies on@id='ep'
is redundant. Also you are making a lot of assumptions here: what if classes are not always int he same order? what ifep
is not static id?
– Kiril S.
Nov 8 at 17:42
add a comment |
up vote
-1
down vote
Instead of absolute xpath you should use relative xpath as follows:
driver.FindElement(By.XPath("//div[@class='bPageBlock brandSecondaryBrd bDetailBlock secondaryPalette' and @id='ep']//div[@class='pbBody']"));
2
checking classes when your element relies on@id='ep'
is redundant. Also you are making a lot of assumptions here: what if classes are not always int he same order? what ifep
is not static id?
– Kiril S.
Nov 8 at 17:42
add a comment |
up vote
-1
down vote
up vote
-1
down vote
Instead of absolute xpath you should use relative xpath as follows:
driver.FindElement(By.XPath("//div[@class='bPageBlock brandSecondaryBrd bDetailBlock secondaryPalette' and @id='ep']//div[@class='pbBody']"));
Instead of absolute xpath you should use relative xpath as follows:
driver.FindElement(By.XPath("//div[@class='bPageBlock brandSecondaryBrd bDetailBlock secondaryPalette' and @id='ep']//div[@class='pbBody']"));
answered Nov 8 at 17:37
DebanjanB
35.4k73271
35.4k73271
2
checking classes when your element relies on@id='ep'
is redundant. Also you are making a lot of assumptions here: what if classes are not always int he same order? what ifep
is not static id?
– Kiril S.
Nov 8 at 17:42
add a comment |
2
checking classes when your element relies on@id='ep'
is redundant. Also you are making a lot of assumptions here: what if classes are not always int he same order? what ifep
is not static id?
– Kiril S.
Nov 8 at 17:42
2
2
checking classes when your element relies on
@id='ep'
is redundant. Also you are making a lot of assumptions here: what if classes are not always int he same order? what if ep
is not static id?– Kiril S.
Nov 8 at 17:42
checking classes when your element relies on
@id='ep'
is redundant. Also you are making a lot of assumptions here: what if classes are not always int he same order? what if ep
is not static id?– Kiril S.
Nov 8 at 17:42
add a comment |
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%2f53212390%2fc-sharp-selenium-xpath-cannot-find-the-inner-div-node%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
2
could you share entire snippet of HTML.
– Ashok kumar Ganesan
Nov 8 at 16:48
The snippet I provided is deep in html - is there a fast way to grab the entire structure?
– Crez43
Nov 8 at 17:40