phpunit-selenium icon indicating copy to clipboard operation
phpunit-selenium copied to clipboard

Set text() function

Open ndeztea opened this issue 11 years ago • 6 comments

Hi There,

I need a function to set html / text inside the div.. as I know phpunit-selenium only has the function for getting the html / text inside the div, by using $this->byId('xxx')->text();

Now my question.. is possible set the html/text inside the div id by using that code like this :

$this->byId('xxx')->text('new value');

Actually I tried this but it Im getting error : invalid json or something..is there any proper function for it?

Thank you

ndeztea avatar Mar 10 '14 13:03 ndeztea

Hi, "text" function is meant to read values. If you want to send a secuence of keys you can use $this->byId('xxx')->value('new value');

You can find a comprehensive list of commands at: https://code.google.com/p/selenium/wiki/JsonWireProtocol

jaruzafa avatar Mar 10 '14 14:03 jaruzafa

Thank you.. I thought the value () function wont work for the div :)..

ndeztea avatar Mar 10 '14 14:03 ndeztea

Wow! You're right, I think value function is only supposed to work on input fields. Let me know your discovers!

jaruzafa avatar Mar 10 '14 14:03 jaruzafa

If I interpret the vision of Selenium 2 correctly, you can only do what a user could (for example invisible elements are not even accessible). So can a user set the text of a div in your page (without Firebug or other plugins)? Usually no, so that's why Selenium does not support value() for generic divs.

giorgiosironi avatar Mar 16 '14 16:03 giorgiosironi

However, I think (without testing it) that if the div is contenteditable then you should be able to focus on it (perhaps $el->click()) and then use $this->keys('abc') to send the keystrokes.

If it's not contenteditable, then you could send some javascript directly; but I'd seriously wonder why you'd want to do that, tbh.

mattparker avatar May 29 '14 10:05 mattparker

well Matt, I havent tried use keys() function.. but thank you for your input.. :)

in my application, i need to edit the text value (innerHTML), but now the feature already changed we are not using element text anymore, we are using standard input instead.. I found which use contenteditable is slower than instead input instead.

ndeztea avatar May 29 '14 23:05 ndeztea