Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to type ampersand "&" in Selenium-2

I want to type the ampersand "&" key in the text-box with selenium web-driver. But selenium-2 looses its focus from type-box while typing the ampersand. My command is, self.type("&", :update => true)

I know that in selenium, keys are sent in UTF_8 format and I have tried to send the equivalent of ampersand but the behavior is still same (as expected). I know XML or HTML supports ampersand with some special escape characters. I want to know is there a way to replace the ampersand with some escape sequence like (HTML code) "&" or "&" in send_keys or type_keys command?

OR is there any other way to type the ampersand "&" in the text-box with selenium-2?

Please let me know your suggestion.

thanks, Sri

like image 629
user1352389 Avatar asked Nov 04 '22 01:11

user1352389


1 Answers

I spent hours on this over multiple days, and eventually @Asaph told me "temporarily remove all of your javascript and see if that is what is causing the ampersand to blank out." He was correct. Now $searchBox->send_keys("bath & body"); works fine.

I eventually narrowed it down to one part of Jquery-ui Autocomplete that was interfering. This property: source:function( request, response ) { //implementation removed } All other javascript could remain in place and work fine. I now want to figure out why Jquery-ui > Autocomplete > Source conflicted with WebDriver and see whether there is a workaround.

like image 103
Ryan Avatar answered Jan 01 '23 20:01

Ryan