2

I'm starting to use Selenium to test my website, but when i'm testing it on Internet Explorer, the function SendKeys("@") write "à" instead of "@".

Otherwise, it's working well on Chrome and FF.

If you have the answer........... :)

Here is my code:

        IWebElement loginInput = driver.FindElement(By.Id("login-inputEl"));
        loginInput.SendKeys("test@test.fr");

Ty!

4 Answers4

1

Try this

loginInput.SendKeys(System.Net.WebUtility.HtmlDecode("test@test.fr"));
Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265
1

I got the solution, in order to write an "@" with selenium in IE Driver! With a french keyboard, you need to press the graph key "ALT GR" and the key "à" to get an "@", then, you'll need to tell Selenium to do the same action.

loginInput.SendKeys("test"); // the beginning of my email adress
var actions = new OpenQA.Selenium.Interactions.Actions(driver);
actions.KeyDown(Keys.Control).KeyDown(Keys.LeftAlt); // I press my graph key "ALT GR"
actions.SendKeys("à"); // Then, my key "@"
actions.KeyUp(Keys.Control).KeyUp(Keys.LeftAlt); // I release my key
actions.Build().Perform(); // execute
loginInput.SendKeys("test.fr"); // the end of my email adress
0

After struggling a couple of days with this same problem, I've found a solution, which is practical and will allow us to enter an email address containing the @ with no hassle.

str email = "username@domain.com"; Driver.Instance.FindElement(By.Name("username")).SendKeys(email);

This should resolve the problem. I was trying to enter the email as var, and was always entering the @ symbols as a q (I have spanish lat kb) and well... str did a good job.

I hope you can use this tip for your Tests!

Ciao.

0

In Java I solved converting the input string in a List of Characters and comparing it with the specials characters.

static String charsSpecial = "@#[]€";

my method is this.

public static void insertValueExplorer(WebDriver driver, WebDriverWait mywait, String locator, String variable) {
        mywait.until(ExpectedConditions.elementToBeClickable(By.xpath(locator))).clear();   
        if(driver.toString().contains("InternetExplorerDriver")){
            List<Character> chars = Utils.convertStringToCharList(variable);
            int j=0;
            while(j<chars.size())
            { 
                if (charsSpecial.contains(chars.get(j).toString())){
                
                    mywait.until(ExpectedConditions.elementToBeClickable(By.xpath(locator))).sendKeys(Keys.chord(Keys.CONTROL, Keys.ALT, chars.get(j).toString())); 
                }else{
                    mywait.until(ExpectedConditions.elementToBeClickable(By.xpath(locator))).sendKeys(chars.get(j).toString()); 
                }
                j=j+1;
            }
        }else {
            mywait.until(ExpectedConditions.elementToBeClickable(By.xpath(locator))).sendKeys(variable);    
        }
    }

I execute my tests on all browsers but this method is necessary only for Explorer

Stupid
  • 135
  • 1
  • 9