duanbei3747 2015-10-26 22:05
浏览 23

使用Selenium和PHP将$插入textarea

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.

Here is an image of the textarea after the selenium command has executed, but before the form has been submitted. Notice that it has skipped the dollar sign, but the rest of the string is in tact.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
    • ¥20 关于URL获取的参数,无法执行二选一查询
    • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
    • ¥15 marlin编译错误,如何解决?
    • ¥15 有偿四位数,节约算法和扫描算法
    • ¥15 VUE项目怎么运行,系统打不开
    • ¥50 pointpillars等目标检测算法怎么融合注意力机制
    • ¥20 Vs code Mac系统 PHP Debug调试环境配置
    • ¥60 大一项目课,微信小程序
    • ¥15 求视频摘要youtube和ovp数据集