0
我試圖自動化一個網站,我可以創建一個列表。 通過在文本字段中輸入值創建列表,然後通過在文本字段外單擊鼠標來設置該值。 然後重複上一步,將更多元素輸入到列表中。 由於我們使用的是Internet Explorer,因此我在IE中使用了Selenium webdriver。 sendKeys方法非常慢,所以我想使用executecript方法。不能使用執行腳本方法與多個參數
我想這樣如下(它不工作),我想知道是否有人有建議。
的代碼片段:
//Here I declare an arry with the values for the list to be created
String valores[] = {"18","25","60","71"};
//Here I get the WebElement where I'm going to enter the above values one by one
WebElement searchField = driver.findElement(By.xpath("//label[text()='New value:']/parent::div//input[@type='text']"));
JavascriptExecutor myExecutor6 = ((JavascriptExecutor) driver);
//Now I’m trying to use a for cycle to enter the values one by one, I need to do this, because this is how the UI works
for(int i=0; i<valores.length; i++){
System.out.println(valores[i]);
Thread.sleep(3000);
/*this part is not working, here what I’m trying to do is: I’m trying to write the value of array valores in position ‘i’ in the text field indicated by the WebElement searchField */
/*I have a javascript error, I do notunderstand what is wrong*/
myExecutor6.executeScript("var valueToWrite = valores[i].toString();"
+"arguments[0].value = valueToWrite ",searchField, valores[i]);
Thread.sleep(3000);
//This step clicks somewhere else with the mouse to enter the value,
driver.findElement(By.xpath("//label[text()='Values:']")).click();
Thread.sleep(3000);
}
什麼是錯誤? – Guy
我改變了代碼,它仍然失敗,然後我在JavaScript中使用focus()方法,它工作。感謝您試圖提供幫助。 (int i = 0; i