Web驱动程序在使用sendkeys时跳过特殊字符 - “(”和“&”)字符 [英] Web driver skips special characters - "(" and "&" characters when using sendkeys

查看:142
本文介绍了Web驱动程序在使用sendkeys时跳过特殊字符 - “(”和“&”)字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

运行测试时,总是被跳过。 C> )。我开始研究它,并尝试所有需要 shift键的特殊字符按(〜!@#$%^& *()发现它总是跳过)。 &。我也在Google搜索框中尝试了相同的测试,在这种情况下,所有的字符都显示出来。



我正在使用Selenium Web驱动程序(2.25.0)+ Java + Firefox(15.0.1)。我也有我的firefox配置文件 setEnableNativeEvents 为false。



我也尝试过使用Internet Explorer,它工作的很好,我想坚持使用firefox,因为我的大部分测试都是在firefox上运行。



关于为什么&)不显示在我测试的Web应用程序中? / p>

以下是我使用的代码:

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

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);


解决方案

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

  driver = new FirefoxDriver(); 
字符串searchKey =TShirt(M);
driver.Navigate()。GoToUrl(http://mywebsite.com/); (searchKey.Contains((and))
{
( [0] .value ='+ searchKey +';,driver.FindElement(By.Id(search_text)));
}
else
{
SendKeys(searchKey);
}

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


As part of my automated tests, I need to type a string with special characters ("(PT books)") into a text box on a web application.

When I run the test, "(" is always skipped. There is no issue with ")". I started investigating it and tried all special characters that require a shift key to be pressed ("~!@#$%^&*()_+{}|:<>?") and found that it always skipped "(" and "&". I also tried the same test on the Google search box and in this case all characters were displayed.

I am using Selenium Web driver(2.25.0) + Java + Firefox(15.0.1). I also have setEnableNativeEvents to false in my firefox profile.

I also tried this using Internet Explorer and it works fine. I would like to stick to firefox as most of my tests run on firefox.

Any ideas as to why "(" and "&" are not displayed on the web application I am testing?

Here is the code that I am using

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);

解决方案

I also faced the same issue. I have a simple workaround for this, which is not the kind of solution i am looking for but time being this helps. If there is a better way to handle please suggest.

        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();

这篇关于Web驱动程序在使用sendkeys时跳过特殊字符 - “(”和“&amp;”)字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆