Xpath using matches and Regex working in Xpath tester but in code throwing InvalidSelectorException Failed to...
up vote
1
down vote
favorite
HTML
<div class="top-section" style="" xpath="1">
<input id="role" value="admin" hidden="">
<small>Welcome </small> <b style="">8828024404, MCGM</b>
<a href=""><img alt="Attendance" width="" height="" src="css/assets/images/logo.png"></img></a>
<a href="/logout" class="float-right logout">Log Out</a>
</input>
</div>
String to search
8828024404, MCGM
Xpath Expression
//b[matches(text(),'[0-9]{10}, [A-Za-z]*')]
Exception
org.openqa.selenium.InvalidSelectorException: invalid selector: Unable
to locate an element with the xpath expression
//b[matches(text(),'[0-9]{10}, [A-Za-z]')] because of the following
error: SyntaxError: Failed to execute 'evaluate' on 'Document': The
string '//b[matches(text(),'[0-9]{10}, [A-Za-z]')]' is not a valid
XPath expression. (Session info: chrome=70.0.3538.102) (Driver
info: chromedriver=2.42.591088
(7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT
10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds
selenium selenium-webdriver xpath
add a comment |
up vote
1
down vote
favorite
HTML
<div class="top-section" style="" xpath="1">
<input id="role" value="admin" hidden="">
<small>Welcome </small> <b style="">8828024404, MCGM</b>
<a href=""><img alt="Attendance" width="" height="" src="css/assets/images/logo.png"></img></a>
<a href="/logout" class="float-right logout">Log Out</a>
</input>
</div>
String to search
8828024404, MCGM
Xpath Expression
//b[matches(text(),'[0-9]{10}, [A-Za-z]*')]
Exception
org.openqa.selenium.InvalidSelectorException: invalid selector: Unable
to locate an element with the xpath expression
//b[matches(text(),'[0-9]{10}, [A-Za-z]')] because of the following
error: SyntaxError: Failed to execute 'evaluate' on 'Document': The
string '//b[matches(text(),'[0-9]{10}, [A-Za-z]')]' is not a valid
XPath expression. (Session info: chrome=70.0.3538.102) (Driver
info: chromedriver=2.42.591088
(7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT
10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds
selenium selenium-webdriver xpath
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
HTML
<div class="top-section" style="" xpath="1">
<input id="role" value="admin" hidden="">
<small>Welcome </small> <b style="">8828024404, MCGM</b>
<a href=""><img alt="Attendance" width="" height="" src="css/assets/images/logo.png"></img></a>
<a href="/logout" class="float-right logout">Log Out</a>
</input>
</div>
String to search
8828024404, MCGM
Xpath Expression
//b[matches(text(),'[0-9]{10}, [A-Za-z]*')]
Exception
org.openqa.selenium.InvalidSelectorException: invalid selector: Unable
to locate an element with the xpath expression
//b[matches(text(),'[0-9]{10}, [A-Za-z]')] because of the following
error: SyntaxError: Failed to execute 'evaluate' on 'Document': The
string '//b[matches(text(),'[0-9]{10}, [A-Za-z]')]' is not a valid
XPath expression. (Session info: chrome=70.0.3538.102) (Driver
info: chromedriver=2.42.591088
(7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT
10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds
selenium selenium-webdriver xpath
HTML
<div class="top-section" style="" xpath="1">
<input id="role" value="admin" hidden="">
<small>Welcome </small> <b style="">8828024404, MCGM</b>
<a href=""><img alt="Attendance" width="" height="" src="css/assets/images/logo.png"></img></a>
<a href="/logout" class="float-right logout">Log Out</a>
</input>
</div>
String to search
8828024404, MCGM
Xpath Expression
//b[matches(text(),'[0-9]{10}, [A-Za-z]*')]
Exception
org.openqa.selenium.InvalidSelectorException: invalid selector: Unable
to locate an element with the xpath expression
//b[matches(text(),'[0-9]{10}, [A-Za-z]')] because of the following
error: SyntaxError: Failed to execute 'evaluate' on 'Document': The
string '//b[matches(text(),'[0-9]{10}, [A-Za-z]')]' is not a valid
XPath expression. (Session info: chrome=70.0.3538.102) (Driver
info: chromedriver=2.42.591088
(7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT
10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds
selenium selenium-webdriver xpath
selenium selenium-webdriver xpath
edited Nov 17 at 20:42
DebanjanB
35.4k73271
35.4k73271
asked Nov 17 at 19:34
Jeevan Nikam
203
203
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
Selenium supports XPath 1.0 version while fn:matches
is from XPath 2.0.
If you want to match bold text that starts with 10 digits before comma, you can try below XPath
//b[string-length(substring-before(., ','))=10 and number(substring-before(., ','))]
Let me know in case you have more constraints to required element
add a comment |
up vote
0
down vote
Quite not sure about your exact usecase why you want a xpath to search for a Regex.
However the resultant text seems to be a part of the Welcome Message and I feel your usecase may be to extract the text which will be dynamic e.g. 8828024404, MCGM.
In this case you can use either of the following solutions:
XPath 1:
//div[@class='top-section']/input[@id='role' and @value='admin']//b
XPath 2:
//div[@class='top-section']/input[@id='role' and @value='admin']/small[contains(.,'Welcome')]//following::b[1]
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Selenium supports XPath 1.0 version while fn:matches
is from XPath 2.0.
If you want to match bold text that starts with 10 digits before comma, you can try below XPath
//b[string-length(substring-before(., ','))=10 and number(substring-before(., ','))]
Let me know in case you have more constraints to required element
add a comment |
up vote
1
down vote
accepted
Selenium supports XPath 1.0 version while fn:matches
is from XPath 2.0.
If you want to match bold text that starts with 10 digits before comma, you can try below XPath
//b[string-length(substring-before(., ','))=10 and number(substring-before(., ','))]
Let me know in case you have more constraints to required element
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Selenium supports XPath 1.0 version while fn:matches
is from XPath 2.0.
If you want to match bold text that starts with 10 digits before comma, you can try below XPath
//b[string-length(substring-before(., ','))=10 and number(substring-before(., ','))]
Let me know in case you have more constraints to required element
Selenium supports XPath 1.0 version while fn:matches
is from XPath 2.0.
If you want to match bold text that starts with 10 digits before comma, you can try below XPath
//b[string-length(substring-before(., ','))=10 and number(substring-before(., ','))]
Let me know in case you have more constraints to required element
answered Nov 17 at 19:57
Andersson
34.8k103066
34.8k103066
add a comment |
add a comment |
up vote
0
down vote
Quite not sure about your exact usecase why you want a xpath to search for a Regex.
However the resultant text seems to be a part of the Welcome Message and I feel your usecase may be to extract the text which will be dynamic e.g. 8828024404, MCGM.
In this case you can use either of the following solutions:
XPath 1:
//div[@class='top-section']/input[@id='role' and @value='admin']//b
XPath 2:
//div[@class='top-section']/input[@id='role' and @value='admin']/small[contains(.,'Welcome')]//following::b[1]
add a comment |
up vote
0
down vote
Quite not sure about your exact usecase why you want a xpath to search for a Regex.
However the resultant text seems to be a part of the Welcome Message and I feel your usecase may be to extract the text which will be dynamic e.g. 8828024404, MCGM.
In this case you can use either of the following solutions:
XPath 1:
//div[@class='top-section']/input[@id='role' and @value='admin']//b
XPath 2:
//div[@class='top-section']/input[@id='role' and @value='admin']/small[contains(.,'Welcome')]//following::b[1]
add a comment |
up vote
0
down vote
up vote
0
down vote
Quite not sure about your exact usecase why you want a xpath to search for a Regex.
However the resultant text seems to be a part of the Welcome Message and I feel your usecase may be to extract the text which will be dynamic e.g. 8828024404, MCGM.
In this case you can use either of the following solutions:
XPath 1:
//div[@class='top-section']/input[@id='role' and @value='admin']//b
XPath 2:
//div[@class='top-section']/input[@id='role' and @value='admin']/small[contains(.,'Welcome')]//following::b[1]
Quite not sure about your exact usecase why you want a xpath to search for a Regex.
However the resultant text seems to be a part of the Welcome Message and I feel your usecase may be to extract the text which will be dynamic e.g. 8828024404, MCGM.
In this case you can use either of the following solutions:
XPath 1:
//div[@class='top-section']/input[@id='role' and @value='admin']//b
XPath 2:
//div[@class='top-section']/input[@id='role' and @value='admin']/small[contains(.,'Welcome')]//following::b[1]
edited Nov 18 at 16:39
answered Nov 17 at 20:44
DebanjanB
35.4k73271
35.4k73271
add a comment |
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%2f53354813%2fxpath-using-matches-and-regex-working-in-xpath-tester-but-in-code-throwing-inval%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