Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用selenium webdriver在标题中插入文本_Javascript_Selenium_Selenium Webdriver - Fatal编程技术网

Javascript 如何使用selenium webdriver在标题中插入文本

Javascript 如何使用selenium webdriver在标题中插入文本,javascript,selenium,selenium-webdriver,Javascript,Selenium,Selenium Webdriver,我有下面的代码 <body> <table> <tr> <td style= "width:30%;"> <img class = "new" src="images/new-icon.png"> <td> <h1>Hello there!</h1> <p>Thanks fo

我有下面的代码

<body>
    <table>
      <tr>
        <td style= "width:30%;">
          <img class = "new" src="images/new-icon.png">
        <td>
            <h1>Hello there!</h1>
          <p>Thanks for logging in
            <span class = "blue">image edit application</span>.
            Get started by reading our
            <a href = "https:abc">documentation</a>
            or use the xxxxxxxxxxxx.
    </table>
  </body>
在上面的代码中,我想在Hello之后添加额外的文本!在标题中使用SeleniumWebDriver和java脚本。请帮忙

我尝试通过xpath定位Hello并尝试使用sendKeys添加文本来点击Hello。我没有看到任何文本添加和代码不会抛出任何错误。
我正在尝试使用selenium在在线编辑器上编辑html文件

尝试使用executeScript函数在浏览器中执行JS。您必须编写一个JavaScript代码来追加/替换文本

我不熟悉Selenium和JS,但这是一个粗略的代码,您可以尝试一下

script = "theParent = document.getElementByTagName('body');
theKid = document.createElement('div');
theKid.innerHTML = 'Hello There!';

// append theKid to the end of theParent
theParent.appendChild(theKid);

// prepend theKid to the beginning of theParent
theParent.insertBefore(theKid, theParent.firstChild);"

driver.executeScript('return ' + script).then(function(return_value) { 
    console.log('returned ', return_value);
});    

请共享您使用selenium编写的发送文本的代码。此外,您只能在文本框、richtext box中插入文本。您正在尝试插入h1标记?似乎不可能。您确定那里的文本是可编辑的吗?它看起来不像是来自您提供的HTML。我尝试添加代码并运行脚本:我得到以下错误:script=theParent=document.getElementByTagName'body';^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^[launcher]错误:语法错误:意外标记ILLEGAL@user5462020-很抱歉,我不熟悉Selenium with JS,但代码看起来与我所做的有些相似。