I have a text area that I have to insert a small snippet of PHP code into, of the format
$value = someFunction("Parameter") . ' and concatenated string.';
However, selenium uses the dollar sign to reference variables, as ${variable_name}
and so it escapes them from text. I tried just inserting the above string, but it always inserts without the dollar sign.
I also tried storing it in a variable, in hopes that using their referencing style would allow me to insert unescaped dollar signs in to the string, but no luck. You also aren't able to escape the $
as it is not a valid JSON escape character.
Note, this is not a duplicate of this question. What they are describing is variable injection into strings in PHP. What I am describing uses Selenium Builder in Firefox to automate actions on a web page. When I use the setElementText
function in Selenium, it will insert text into a textarea. There just happens to be a $
in my text, however, and this is a reserved character for Selenium to identify variables (using the above syntax), so when setElementText is executed, the $
is stripped from the text (note: BEFORE the form has been submitted, this is not PHP rendering the text incorrectly, it never has the $
inserted at any point beyond the JSON file it is read from).
UPDATE
Here are some additional details.
This is the JSON command that stores a variable in selenium. The "text" being stored is the string I want to insert into the textarea
{
"type": "store",
"text": "$value = 'Number of People: ' . count(\"Person\");",
"variable": "php_derived_value"
}
And to access that, we can do something like this:
{
"type": "setElementText",
"locator": {
"type": "css selector",
"value": "div > textarea"
},
"text": "${php_derived_value}"
}
Notice that this dollar sign is used as an escape character to reference the variable. The problem lies with the fact that the text I am inserting will then skip the dollar sign.