这是我的代码。 该代码适用于firefox,但是当我在google chrome上运行它时,浏览器会打开并识别用户名字段,但不会从excel中读取数据并将其发送到元素。
package test_script;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import common_functions.commonFunctionRepo;
import common_objects.*;
import excel_utilites.ExcelUtils;
import utilities.Constant;
public class AddPgm_TC_02
{
@Test
public void AddPgm() throws Exception
{
//Set Test browser to Firefox driver
System.setProperty("webdriver.chrome.driver", "./exe_files/chromedriver.exe");
WebDriver driver = new ChromeDriver();
//WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
//Launch the url
commonFunctionRepo.launchDucky(driver);
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
ExcelUtils.setExcelFile(Constant.Path_TestData + Constant.File_TestData, "TC_02");
for (int i=1; i<=ExcelUtils.getRowcount(); i++)
{
String Uname = ExcelUtils.getCellData(i, 1);
String Pwd = ExcelUtils.getCellData(i, 2);
//Login
commonFunctionRepo.login(driver, Uname,Pwd);
System.out.println("Logged in Successfully");
String pgmNameTxt = ExcelUtils.getCellData(i, 3);
String descTxt = ExcelUtils.getCellData(i, 4);
String expRes = ExcelUtils.getCellData(i, 5);
//Click on Menu
WebElement menu = driver.findElement(By.id("vappmenu"));
menu.click();
//Click on Navigation
WebElement navigation = driver.findElement(By.cssSelector("paper-icon-item[title='Navigation']"));
navigation.click();
//Click on Manage Program
WebElement subManagePgm = driver.findElement(By.id("Manage Programs"));
subManagePgm.click();
System.out.println("Navigated Manage Program Successfully");
//Click on Add New button - need id
WebElement addNew = driver.findElement(By.cssSelector("iron-icon[class='style-scope programs-panel x-scope iron-icon-1'][icon='add-box']"));
addNew.click();
//Type Program Name
WebElement pgmName = driver.findElement(By.cssSelector("input[title='Program Name']"));
commonFunctionRepo.SendData(driver, pgmName, pgmNameTxt);
//Type Description - need id
WebElement desc = driver.findElement(By.cssSelector("paper-textarea[class='program-upsert-full style-scope program-upsert'][label='Description']"));
commonFunctionRepo.SendData(driver, desc, descTxt);
//Click on Save
WebElement saveBtn = driver.findElement(By.cssSelector("paper-button[title='Save Program']"));
saveBtn.click();
//Get Success Message - need id
WebElement successMsg = driver.findElement(By.cssSelector("paper-toast[title = 'Program created successfully']>span[id='label'][class='style-scope paper-toast']"));
String msg = commonFunctionRepo.getTextFrom(driver, successMsg);
System.out.println("Message is - "+msg);
//logout
driver.findElement(By.id("vappmenu")).click();
driver.findElement(By.xpath("//paper-item[@title='Logout']")).click();
Boolean status = commonFunctionRepo.strCompare(msg, expRes);
ExcelUtils.setCellData(msg, i, 6);
if(status)
{
ExcelUtils.setCellData("pass", i, 7);
}
else enter code here
{
ExcelUtils.setCellData("Fail", i, 7);
}
}
driver.close();
}
}
控制台错误:
org.openqa.selenium.WebDriverException: unknown error: cannot focus element
(Session info: chrome=55.0.2883.87)
(Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 133 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:32:46'
System info: host: 'DESKTOP-0436FTE', ip: '192.168.0.3', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed), userDataDir=C:\Users\khaji\AppData\Local\Temp\scoped_dir272_9014}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=55.0.2883.87, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 4771cb9a4b4ab55ebe166a8fee9a4414