How to enter left parentheses in a text box

I have a requirement to pass the text "English (USA)" to the text box. But when I use the command below:

driver.findElement(By.id("defaultLang")).sendKeys("English (United States)");

Only "US English" is entered in the text box . There are no open parentheses when WebDriver writes text to a text field.

+4
source share
3 answers

Using this, you can enter a left bracket in the text box.

    String a = (Keys.chord(Keys.SHIFT,"9"));
    String b = "AAA";
    String c = "BBB)";
    driver.findElement(By.id("ID")).sendKeys(b+a+c);

Resulting O / P: AAA (BBB)

+2
source

You must use escape to send special characters in the selenium web driver,

I think you can try something like this:

driver.findElement(By.id("defaultLang")).sendKeys("English \(United States\)");

, .

0

. . 6822 .

Now you can install it by directly entering JavaScript.

// untested Java code, provides only the logic, you need debug yourself
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].setAttribute('value', arguments[1]);", driver.findElement(By.id("defaultLang")), "English (United States)");
0
source

Source: https://habr.com/ru/post/1529968/


All Articles