Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.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,Java:在Safari和Firefox上的文本框中输入值_Javascript_Java_Firefox_Selenium_Safari - Fatal编程技术网

Javascript Selenium,Java:在Safari和Firefox上的文本框中输入值

Javascript Selenium,Java:在Safari和Firefox上的文本框中输入值,javascript,java,firefox,selenium,safari,Javascript,Java,Firefox,Selenium,Safari,在Chrome中,我可以将文本输入到字段中的唯一方法是使用操作。但是,这在Safari和Firefox上不起作用 应用程序中输入的代码如下所示: <div id="5712825281899484" class="location-input ace_editor ace-tm"> <textarea class="ace_text-input" wrap="off" autocorrect="off" autocapitalize="off" spellcheck="fals

在Chrome中,我可以将文本输入到字段中的唯一方法是使用
操作
。但是,这在
Safari
Firefox
上不起作用

应用程序中输入的代码如下所示:

<div id="5712825281899484" class="location-input ace_editor ace-tm">
<textarea class="ace_text-input" wrap="off" autocorrect="off" autocapitalize="off" spellcheck="false" style="opacity: 0; height: 16px; width: 7.2px; left: 45px; top: 0px;"/>
<div class="ace_gutter">
<div class="ace_layer ace_gutter-layer ace_folding-enabled" style="margin-top: 0px; height: 180px; width: 41px;">
<div class="ace_gutter-cell " style="height: 16px;">1</div>
</div>
<div class="ace_gutter-active-line" style="top: 0px; height: 16px;"/>
</div>
<div class="ace_scroller" style="left: 41px; right: 0px; bottom: 0px;">
<div class="ace_content" style="margin-top: 0px; width: 444px; height: 180px; margin-left: 0px;">
</div>
我在Chrome中使用了操作,在这里我可以输入值:

Actions action = new Actions(webDriver);
action.moveToElement(txtLocation);
action.click();
action.sendKeys(location).build().perform();
在firefox中,“操作”不起作用:selenium只是继续执行而不输入文本,并且不报告错误

但是,在safari中,当我使用“
操作
”时,会出现以下错误:

org.openqa.selenium.WebDriverException: Unknown command: {"id":"60ej2zi96iqs","name":"mouseMoveTo","parameters":{"element":":wdc:1455640284141"}} (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 4 milliseconds
JAVASCRIPT 我也在Safari和Firefox中尝试过javascriptexecutor,但仍然不走运。这是javascript中的代码:

JavascriptExecutor jsExecutor = (JavascriptExecutor) webDriver;
tempWebElement = webDriver.findElement(By.xpath("//div[@class='ace_layer ace_text-layer']"));
jsExecutor.executeScript("document.getElementsByClassName('ace_line').value = '"+ location + "';");
上面的代码不输入文本,在Selenium中运行时不会引发任何错误

我花了很多时间试图解决这个问题。任何帮助都是有用的

Selenium version: 2.48.2
试试这个:

String xpath = "//div[@class='ace_content']//div[2] /child::div[@class='ace_active-line']";
String inputValue = //whatever you want to input

FirefoxDriver driver = new FirefoxDriver();
driver.findElement(by.xpath(xpath)).sendKeys(inputValue );

我认为这是firefox浏览器的问题,因为firefox会自动更新到最新版本。因此,我建议您卸载最新的浏览器版本,并安装Firefox旧版本,如38.0

String xpath = "//div[@class='ace_content']//div[2] /child::div[@class='ace_active-line']";
String inputValue = //whatever you want to input

FirefoxDriver driver = new FirefoxDriver();
driver.findElement(by.xpath(xpath)).sendKeys(inputValue );