Java Web驱动程序跳过特殊字符-“;(“和”字符,当使用SendKey时

Java Web驱动程序跳过特殊字符-“;(“和”字符,当使用SendKey时,java,firefox,selenium-webdriver,Java,Firefox,Selenium Webdriver,作为自动化测试的一部分,我需要在web应用程序的文本框中键入一个带有特殊字符的字符串(“PT books”) 当我运行测试时,“(“总是被跳过。没有问题””。我开始研究它,并尝试了所有需要按下shift键的特殊字符(“~!@$%^&*”),发现它总是跳过”(“和”&“。我还在谷歌搜索框上尝试了相同的测试,在本例中,所有字符都显示出来 我使用的是Selenium Web驱动程序(2.25.0)+Java+Firefox(15.0.1)。在我的Firefox配置文件中,我还将设置为false 我也尝

作为自动化测试的一部分,我需要在web应用程序的文本框中键入一个带有特殊字符的字符串(“PT books”)

当我运行测试时,
“(“
总是被跳过。
没有问题”
”。我开始研究它,并尝试了所有需要按下
shift键的特殊字符(“~!@$%^&*”)
,发现它总是跳过
”(“
”&“
。我还在谷歌搜索框上尝试了相同的测试,在本例中,所有字符都显示出来

我使用的是Selenium Web驱动程序(2.25.0)+Java+Firefox(15.0.1)。在我的Firefox配置文件中,我还将
设置为false

我也尝试过使用Internet Explorer,效果很好。我想坚持使用firefox,因为我的大多数测试都在firefox上运行

关于我正在测试的web应用程序上为什么没有显示
(“
”&“
”)有什么想法吗

这是我正在使用的代码

FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents( false);
WebDriver driver = new FirefoxDriver(profile);

String searchTerm = "~!@#$%^&*()_+{}|:<>?" ;

String Link = "http://" ;

driver.get( "http://www.google.com");
driver.findElement(By. id("gbqfq")).sendKeys(searchTerm);

driver.get(Link);
driver.findElement(By. id("ctl00_ctl00_FindField_FindField_ctl00_findFieldLinks_basic")).click();
driver.findElement(By. id(UIMapping.SearchBoxId)).sendKeys(searchTerm);
FirefoxProfile profile=新的FirefoxProfile();
profile.setenablenactiveEvents(false);
WebDriver=新的FirefoxDriver(配置文件);
String searchTerm=“~!@$%^&*()”(+{}}:?”;
String Link=“http://”;
驱动程序。获取(“http://www.google.com");
driver.findElement(By.id(“gbqfq”)).sendKeys(searchTerm);
获取(链接);
driver.findElement(By.id(“ctl00\u ctl00\u FindField\u FindField\u ctl00\u findFieldLinks\u basic”)。单击();
driver.findElement(By.id(UIMapping.SearchBoxId)).sendKeys(searchTerm);

我也面临着同样的问题。我有一个简单的解决方法,这不是我正在寻找的解决方案,但目前这很有帮助。如果有更好的方法处理,请提出建议

        driver = new FirefoxDriver();
        String searchKey = "TShirt(M)";
        driver.Navigate().GoToUrl("http://mywebsite.com/");

        if (searchKey.Contains("(") || searchKey.Contains("&"))
        {
            ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].value ='" + searchKey + "';", driver.FindElement(By.Id("search_text"))); 
        }
        else
        {
            driver.FindElement(By.Id("search_text")).SendKeys(searchKey);
        }

        driver.FindElement(By.Id("search_button")).Click();

这只是一种预感——但您是否尝试过使用URLEncoder对它们进行编码?我尝试了URLEncoder和解码器,但都不起作用。