使用UTF-8 - IllegalArgumentException:找不到具有null id属性的元素

时间:2017-09-01 05:46:29

标签: eclipse selenium selenium-webdriver

我的Selenium-Java项目正在使用15种不同的语言。我的测试将根据我在启动浏览器之前设置的语言执行。使用Eclipse编写代码。

由于文本不同,根据文本,我正在识别元素并在文本字段中输入文本。例如,对于英国而言,它是“城市”,但对于意大利而言,它是“Città”。 注意:我无法直接使用定位器,因为文本/问卷调查将在这些语言之间有不同的位置。

我必须使用的文件编码是UTF-8。

当我执行它时,它的错误为'IllegalArgumentException:找不到具有null id属性的元素。'请纠正我错在哪里。

下面的课程是访问要在问题栏中输入的测试数据。

public class GetQuestionLocator {
public static String getLocator(String questionname) {
String locatorvalue = null;
switch (questionname) {
//Building Information Questions
  case "Site name": //UK
  case "Name des Standorts":  //Germany, Austria
  case "Building #":  //Italy
  case "Naam locatie": //nld
  case "Kohteen nimi": //Finland
  case "Nombre de la instalación":  //Spain, Andorra, Marvi
  case "Platsnamn":  //Sweden
  case "Nome da instalação":  //Portugal
  case "Stedets navn":  //Denmark
    locatorvalue = AssessmentPageData.BuildingDescription;
    break;
  case "Street address": //UK
  case "Straße": //Germany, Austria
  case "Edificio": //Italy
  case "Straatnaam": //nld
  case "Katuosoite": //Finland
  case "Dirección":  //Spain, Andorra, Marvi
  case "Gatuadress":  //Sweden
  case "Direcção":  //Portugal
  case "Vejnavn":  //Denmark
    locatorvalue = AssessmentPageData.BuildingAddress;
    break;
  case "City": //UK
  case "Ort":  //Germany, Austria
  case "Città":  //Italy
  case "Plaats": //nld
  case "Kaupunki": //Finland
  case "Ciudad":  //Spain, Andorra, Marvi
  case "Stad":  //Sweden
  case "Cidade":  //Portugal
  case "By":  //Denmark
    locatorvalue = AssessmentPageData.BuildingCity;
    break;
}

下面是我如何映射Excel数据和定位器。

public void provideBuildingDetails(String FL) throws InterruptedException {
        String SiteName = null;
        String StreetAddress = null;
        String City = null;
        String PostalCode = null;
        String Country = null;
        String BuildingDescription = null;
        String BuildingAddress = null;
        String BuildingCity = null;
        String BuildingPostalCode = null;
        String BuildingCountry = null;
        switch (FL) {
        case "UK":
            SiteName = Xls_Reader.getData("UKBuildingQuestions", "BuildingInformationQuestions", "SiteName");
            StreetAddress = Xls_Reader.getData("UKBuildingQuestions", "BuildingInformationQuestions","StreetAddress");
            City = Xls_Reader.getData("UKBuildingQuestions", "BuildingInformationQuestions", "City");
            PostalCode = Xls_Reader.getData("UKBuildingQuestions", "BuildingInformationQuestions", "PostalCode");
            Country = Xls_Reader.getData("UKBuildingQuestions", "BuildingInformationQuestions", "Country");
            BuildingDescription = Xls_Reader.getData("UKBuildingQuestions", "ProvideBuildingDetails","BuildingDescription");
            BuildingAddress = Xls_Reader.getData("UKBuildingQuestions", "ProvideBuildingDetails","BuildingAddress");
            BuildingCity = Xls_Reader.getData("UKBuildingQuestions", "ProvideBuildingDetails", "BuildingCity");
            BuildingPostalCode = Xls_Reader.getData("UKBuildingQuestions", "ProvideBuildingDetails","BuildingPostalCode");
            BuildingCountry = Xls_Reader.getData("UKBuildingQuestions", "ProvideBuildingDetails","BuildingCountry");
            break;

        case "Italy":
            SiteName = Xls_Reader.getData("ItalyBuildingQuestions", "BuildingInformationQuestions", "SiteName");
            StreetAddress = Xls_Reader.getData("ItalyBuildingQuestions", "BuildingInformationQuestions","StreetAddress");
            City = Xls_Reader.getData("ItalyBuildingQuestions", "BuildingInformationQuestions", "City");
            PostalCode = Xls_Reader.getData("ItalyBuildingQuestions", "BuildingInformationQuestions", "PostalCode");
            Country = Xls_Reader.getData("ItalyBuildingQuestions", "BuildingInformationQuestions", "Country");
            BuildingDescription = Xls_Reader.getData("ItalyBuildingQuestions", "ProvideBuildingDetails","BuildingDescription");
            BuildingAddress = Xls_Reader.getData("ItalyBuildingQuestions", "ProvideBuildingDetails","BuildingAddress");
            BuildingCity = Xls_Reader.getData("ItalyBuildingQuestions", "ProvideBuildingDetails", "BuildingCity");
            BuildingPostalCode = Xls_Reader.getData("ItalyBuildingQuestions", "ProvideBuildingDetails","BuildingPostalCode");
            BuildingCountry = Xls_Reader.getData("ItalyBuildingQuestions", "ProvideBuildingDetails","BuildingCountry");
            break;
            }
        ClickOnElement("id", AssessmentPageData.BuildingQuestionGroupInfo);
        String locator = GetQuestionLocator.getLocator(SiteName);
        EnterValuesByIndex("id", locator, BuildingDescription, 1);
        locator = GetQuestionLocator.getLocator(StreetAddress);
        EnterValuesByIndex("id", locator, BuildingAddress, 1);
        locator = GetQuestionLocator.getLocator(City);
        EnterValuesByIndex("id", locator, BuildingCity, 1);
        locator = GetQuestionLocator.getLocator(PostalCode);
        EnterValuesByIndex("id", locator, BuildingPostalCode, 1);
        locator = GetQuestionLocator.getLocator(Country);
        EnterValuesByIndex("id", locator, BuildingCountry, 1);
    }

在意大利的Excel中, enter image description here

例外情况如下图所示, enter image description here

1 个答案:

答案 0 :(得分:0)

通过以下步骤纠正了此问题,

  1. Goto Eclipse-> Window-> Preferences-> editor-> Click TextEditor
  2. 点击拼写
  3. 在“编码”部分下选择“其他”,然后从下拉列表中选择“UTF-8”。
  4. 点击“应用”
  5. 重启Eclipse