I want to print all lines starting with a "+" and which have a keyword such as "hasRole".
String search="//td[contains(#class,'blob-code blob-code-addition') and contains(text(),'hasRole')]";
I know a simple and condition will not be enough. How do I formulate the XPATH search for this?
Here's a screenshot.
Also,how do I make this search case insensitive?
You can use something like this:
//td[(contains(lower-case(#class), 'blob-code blob-code-addition') ...
OR
//td[(contains(translate(#class, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz"), 'blob-code blob-code-addition') ...
I tried the below and it worked.
String search="//td[(contains(#class,'blob-code blob-code-addition') and contains(.,'HasRole')) or (contains(#class,'blob-code blob-code-deletion') and contains(.,'HasRole'))]";
Related
As you are able to see, I have used one dynamic xpath: //td[text()='Discharge Air']/following-sibling::td/span to go from zone1 until zone3, but when I am using gettext() to fetch only 100 but special character °F is also coming. Hence please suggest how to remove this special character °F, because I want only data 100 from this xpath? As you can see in the image, only 1 span is available, so I can't separate span also.
String s = driver.findElement(By.xpath("//td[text()='Discharge Air']/following-sibling::td/span")).getText();
s.replace("°F","");//replace the °F with empty string
Instead of String, can i use List because all these xpath are of same type,hence directly i can write and afterwards i can use for loop for getText().
List s=driver.findElements(By.xpath("//td[text()='Discharge Air']/following-sibling::td/span"));
s.replace("°F","");
Thanks in advance,
List disch_Air = driver.findElements(By.xpath("//td[text()='Discharge Air']/following-sibling::td/span"));
for(int i=0;i<disch_Air.size();i++) {
System.out.println(disch_Air.get(i).getText().replace("°F", ""));
}
}
This is what i want and its working fine thank you so much guys for ur help
Use this:
//first find the elements and save it as you did (with the xpath you posted)
String s = driver.findElement(By.xpath("//td[text()='Discharge Air']/following-sibling::td/span")).getText();
s.replace("°F","");//replace the °F with empty string
and if you see that there are still spaces on your string you can use this to remove them:
s.trim();
I currently working on translating a website (Smarty) with Poedit. To get all the text from the .tpl files i'm using regex to get the data between the {t} and {/t}. so an example:
{t}Password incorrect, please try again{/t}
The regex will read Password incorrect, please try again and place it in a .po file. This is all working fine. It goes wrong when it gets a little more advanced.
Sometimes the text between the {t} tags uses a parameter. this looks like this:
{t 1=$email|escape 2=$mailbox}No $1 given, please check your $2{/t}
This is also working great.
The real problem start when i use brackets inside the parameter like this:
{t 1={site info='name'} 2=$mailbox}visit %1 or go to your %2{/t}
My regex will close when it sees the first closing brackets so the result will be 2=$mailbox}visit %1 or go to your %2.
My regex looks like this:
\{t.*?\}?[}]([^\{]+)\{\/t\}|\{t\}([^\{]+)\{\/t\}
The regex is used inside a java program.
Does anybody has a way to fix this problem?
The easiest solution I see on this is to normalize the .tpl files. Just use a regex which matches all tags something like this one:
{[^}]*[^{]*}
I had the same issue to solve and it worked pretty good with the normalizing.
The normalizing-method would look like this:
final String regex = "\\{[^\\}]*[^\\{]*\\}";
private String normalizeContent(String content) {
return content.replaceAll(regex, "");
}
I am trying to extract the pass number from strings of any of the following formats:
PassID_132
PassID_64
Pass_298
Pass_16
For this, I constructed the following regex:
Pass[I]?[D]?_([\d]{2,3})
-and tested it in Eclipse's search dialog. It worked fine.
However, when I use it in code, it doesn't match anything. Here's my code snippet:
String idString = filename.replaceAll("Pass[I]?[D]?_([\\d]{2,3})", "$1");
int result = Integer.parseInt(idString);
I also tried
java.util.regex.Pattern.compile("Pass[I]?[D]?_([\\d]{2,3})")
in the Expressions window while debugging, but that says "", whereas
java.util.regex.Pattern.compile("Pass[I]?[D]?_([0-9]{2,3})")
compiled, but didn't match anything. What could be the problem?
Instead of Pass[I]?[D]?_([\d]{2,3}) try this:
Pass(?:I)?(?:D)?_([\d]{2,3})
There's nothing invalid with your tegex, but it sucks. You don't need character classes around single character terms. Try this:
"Pass(?:ID)?_(\\d{2,3})"
Need regular expression to extract the values between >xxxxx<. Can anybody help me in this.
<ChangeID type="String">C10286</ChangeID>
<ChangeID type="String">C10296</ChangeID>
Is it possible to get the two values in a comma separated format like C10286,C10296 in a single regex expression?
Thanks and Regards
Riyas Hussain A
try this:
(?<=>)[^<]*
test it with grep -Po:
kent$ echo '<ChangeID type="String">C10286</ChangeID>
<ChangeID type="String">C10296</ChangeID>'|grep -Po '(?<=>)[^<]*'
C10286
C10296
My idea would be to lookup for all words and remove the ones we don't need (in case you have more than 1 value inside your tag):
(?!ChangeID\b)(?!type\b)(?!String\b)\b\w+
You can try it out on : http://regexpal.com/
I want to catch the value of some HTML tag.
that could look like this:
value='3242312-3245-3245,234:3245:324,asdf asdf,asdf asd'>
or like this:
value=358 >
and maybe this:
value=83 selected='selected'>
I tried:
Pattern.compile("value=[[\'(.+)\'][(0-9)\\s]]")
but with no success...
any idea what pattern should I use?
This expression should work:
(?<field>\w+)=(('(?<value>[^']*)')|(?<value>\S+))
You can test here using the same expression w/o group names (since the tool doesn't support them):
(\w+)=(('([^']*)')|(\S+))