I am testing site with selenium and I need to send an e-mail to one of the fields. So far I am using this Java method:
String email = "test#example.com"
WebElement emailField = driver.findElement(By.id("mainForm:accountPanelTabId:1:accountEmails");
emailField.sendKeys(email);
But from (to me) uknown reason, this is sending exactly this value to the field:
testvexample.com
(so basically the "#" got replaced by "v")
Just out of curiosity: I am Czech and have Czech keyboard. One shortcut to write "#" symbol is rightAlt + v so I believe this can be connected...
So I am searching any "bulletproof" methot which always writes "#" symbol. Any help appreciated.
EDIT
the sendKeys is method of Selenium, and it simulates typing on keyboard. The javadoc is here: http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebElement.html#sendKeys%28java.lang.CharSequence...%29
The following should work: String email = "test\u0040example.com";
Apologies for misreading the question earlier.
I think you will have to call sendKeys using the proper values from the Keys enum to simulate the way you get your at-sign. Use Keys.ALT with your "v" in a chord:
sendKeys(Keys.chord(Keys.ALT, "v"));
Related
I use some codes like temp_out.setText(response.body().getCurrent().getTemp() + " ℃"); to get data from a weather API, but got two lint errors:
Do not concatenate text displayed with set text. Use resource placeholders only.
String literals in setText can not be translated. Use Android resources instead.
So i searched here for similar errors on this site and partly found a solution here https://stackoverflow.com/a/35053689/13899010,
I used this one because I didn't want using resource String to change the data displayed. Added this to String.xml:
<string name="blank">%d</string> then Changed my code to this:
temp_out.setText(getString(R.string.blank, response.body().getCurrent().getTemp() + " ℃"));
Now i get this error Wrong argument type for formatting argument '#1' in blank: conversion is 'd', received string (argument #2 in method call).
I saw similar question Android Studio "Wrong argument type for formatting Error" in String.format() but his solution didn't work for me. How to fix this please?
make sure response.body().getCurrent().getTemp() returning a int, if its a string use %s in string blank
you can try one of the following
<string name="blank">%d Celsius</string>
//invoking as follows
getString(R.string.blank, response.body().getCurrent().getTemp())
temp_out.setText("${response.body().getCurrent().getTemp()} Celsius")
I am using selenium to verify a web site where doctors' names appear in a drop-down box. If the name in the database has extra spaces (like "Kildare , Jack , MD") the blanks should be removed like "Kildare, Jack MD". I am using the selenium method select.getOptions() (where select is the web element of a select box).
When I retrieve the date from the box and print it, it shows the names as still having spaces (see Alois Alzheimer and Sigmund Freud below). In the text box visually it shows Sigmund Freud formatted correctly, but Alois Alzhemier still has a space after Alois (see the attached picture). I am not sure what is happening here. Looks like the select box occasionally removes blanks itself and sometimes doesn't. Any clues?
Here is the debug text from select box:
DEBUG [PP21644] ----<Alzheimer, Alois , DO>-----
DEBUG [PP21644] ----<Freud, Sigmund Schlomo, Jr, MD>-----
DEBUG [PP21644] ----<Mayo, Charles Mayo, MMIN>-----
And the picture of how it looks is attached. Sigmund is formatted correctly but Alois is not (see the space highlighted with a yellow square). And yes, I had to run this with famous doctors' names to protect the names of the actual providers.
There are a few ways you could do this
You could examine the HTML of the OPTIONs and figure out where the spaces are coming from, parse it, etc. to get rid of the spaces. I can't really offer code here since I don't know what the HTML looks like.
Another way given what you provided is to use regex and .replace() to remove repeated spaces and to remove a space before a comma.
public static void main(String[] args)
{
String s1 = "Alzheimer, Alois , DO";
String s2 = "Freud, Sigmund Schlomo, Jr, MD";
String s3 = "Mayo, Charles Mayo, MMIN";
System.out.println(cleanup(s1));
System.out.println(cleanup(s2));
System.out.println(cleanup(s3));
}
public static String cleanup(String s)
{
return s.replaceAll(" +", " ").replace(" ,", ",");
}
I am writing some auto test using Web Driver to find text on page.
I have variable address - with value Some one, Address
And text on page Some One, Address
Difference only in One and one
but my regex not working
...get(LINK, "regexp:(?i)("+address+")").exists(); // should return boolean
Please, help me to resolve this problem,
Thanks
Try this:
String base = "Some One, Address";
System.out.println(base.matches("(?i:.*address.*)"));
I am running in to bit of a trouble trying to use parametric replacement.
In my properties file I have the following entry
tpi.message=This is a test message. Generated for ? on ? .
The text above is displayed on the web and in the report therefore I need to replace ? with parameters.
However, I can't use replace* method because ? is special character for regex. I also don't want to use String.format method.
I know it is possible to replace ? but I don't remember how.
Your help is appreciated.
You can do it like this:
String message = "This is a test message. Generated for ? on ?";
message = message.replaceFirst("\\?", "Bob").replaceFirst("\\?", "Tuesday");
System.out.println(message); // This is a test message. Generated for Bob on Tuesday
I have the following REGEX that I'm serving up to java via an xml file.
[a-zA-Z -\(\) \-]+
This regex is used to validate server side and client side (via javascript) and works pretty well at allowing only alphabetic content and a few other characters...
My problem is that it will also allow zero lenth strings / empty through.
Does anyone have a simple and yet elegant solution to this?
I already tried...
[a-zA-Z -\(\) \-]{1,}+
but that didn;t seem to work.
Cheers!
UPDATE FOLLOWING INVESTIGATION
It appears the code I provided does in fact work...
String inputStr = " ";
String pattern = "[a-zA-Z -\\(\\) \\-]+";
boolean patternMatched = java.util.regex.Pattern.matches(pattern, inputStr);
if ( patternMatched ){
out.println("Pattern MATCHED");
}else{
out.println("NOT MATCHED");
}
After looking at this more closely I think the problem may well be within the logic of some of my java bean coding... It appears the regex is dropped out at the point where the string parse should take place, thereby allowing empty strings to be submitted... And also any other string... EEJIT that I am...
Cheers for the help in peer reviewing my initial stupid though....!
Have you tried this:
[a-zA-Z -\(\) \-]+