Getting Data From Excel Sheet | Selenium Forum
M
Posted on 01/03/2016
Hi

ERROR : The given selector //*[@id='dnn1479root']/div/div[1]/div[2]/div/div[]/label is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: Unable to locate an element with the xpath expression //*[@id='dnn1479root']/div/div[1]/div[2]/div/div[]/label because of the following error:


I have a two dropdown values selecting data from excel sheet. How to getting a data from single excel sheet.herewith i have attached the code and screenshot of excel sheet


Code:
//Getting data from Excel sheet - Select Commission Types

xls_reader Commissiondata = new xls_reader("E:\\Workspace\\IGM\\src\\Test\\Data.xlsx");
String CommissionValues = Commissiondata.getCellData("CommissionTypes","Selected_Commission_Types",2);
String CommissionSelections[] = CommissionValues.split(",");
String Commissionxpath_start = "//*[@id='dnn1479root']/div/div[1]/div[1]/div/div[";
String Commissionxpath_end = "]/label";
for(int i =1;i<=CommissionSelections.length;i++)
Driver.findElement(By.xpath(Commissionxpath_start+CommissionSelections[i-1]+Commissionxpath_end)).click();


//Getting data from Excel sheet - Select Additional options - Commission Types

xls_reader Addtionaldata = new xls_reader("E:\\Workspace\\IGM\\src\\Test\\Data.xlsx");
String AdditionalValues = Addtionaldata.getCellData("CommissionTypes","Additional_Types",8);
String AdditionalSelections[] = AdditionalValues.split(",");
String Additionalxpath_start = "//*[@id='dnn1479root']/div/div[1]/div[2]/div/div[";
String Additionalxpath_end = "]/label";
for(int j =1;j<=AdditionalSelections.length;j++)
Driver.findElement(By.xpath(Additionalxpath_start+AdditionalSelections[j-1]+Additionalxpath_end)).click();

M
Replied on 02/03/2016

[quote:1fr8zewy]InvalidSelectorError: Unable to locate an element with the xpath expression //*[@id='dnn1479root']/div/div[1]/div[2]/div/div[]/label because of the following error:
[/quote:1fr8zewy]

this error comes when your selector is wrong. it has nothing to do with excel.