Java Selenium webdriver未通过对象存储库文件定位元素

Java Selenium webdriver未通过对象存储库文件定位元素,java,xpath,selenium-webdriver,Java,Xpath,Selenium Webdriver,我正在通过一个对象文件在SeleniumWebDriver中搜索一个元素。除一个元素外,所有其他元素都将被返回。我已尝试将定位器配置为xpath、cssselector和name等 当我试图通过id或任何其他定位器直接从控制台定位元素时,它被成功定位。只是不通过对象文件 对象文件和控制台中的所有信息都是正确的 以下是对象文件内容: one=.//*[@id='1'] two=.//*[@id='2'] three=.//*[@id='3'] four=.//*[@id='4'] five=

我正在通过一个对象文件在SeleniumWebDriver中搜索一个元素。除一个元素外,所有其他元素都将被返回。我已尝试将定位器配置为xpath、cssselector和name等

当我试图通过id或任何其他定位器直接从控制台定位元素时,它被成功定位。只是不通过对象文件

对象文件和控制台中的所有信息都是正确的

以下是对象文件内容:

one=.//*[@id='1'] 
two=.//*[@id='2'] 
three=.//*[@id='3']
four=.//*[@id='4'] 
five=.//*[@id='5'] 
six=.//*[@id='6'] 
seven=.//*[@id='7'] 
eight=.//*[@id='8'] 
nine=.//*[@id='9']
zero=.//*[@id='0']
equalsto=.//*[@id='equals'] 
cler=.//*[@id='AC']
result=.//*[@id='Resultbox']
plus=.//*[@id='plus'] 
minus=.//*[@id='minus'] 
mul=.//*[@id='multiply']
heading=.//*[@id='Blog1']/div[1]/div/div/div/div[1]/h3
以下是代码:

public class CalcTest {
    WebDriver driver = new FirefoxDriver();

    @BeforeMethod
    public void openbrowser() throws IOException, InterruptedException {
        driver.manage().window().maximize();
        driver.get("http://only-testing-blog.blogspot.in/2014/04/calc.html");
    }

    /*@AfterMethod
    public void closebrowser() {
        driver.quit();
    }*/

    @Test
    public void Calc_Operations() throws IOException, InterruptedException {
        // Create Object of Properties Class.
        Properties obj = new Properties();
        // Create Object of FileInputStream Class. Pass file path.
        FileInputStream objfile = new FileInputStream(
                System.getProperty("user.dir") + "\\src\\Objects\\objects.properties");
        // Pass object reference objfile to load method of Properties object.
        obj.load(objfile);

        // Sum operation on calculator.
        // Accessing element locators of all web elements using
        // obj.getProperty(key)

        String heading = driver.findElement(By.xpath(obj.getProperty("heading"))).getText();
        System.out.println(heading);
        driver.findElement(By.xpath(obj.getProperty("eight"))).click();
        driver.findElement(By.xpath(obj.getProperty("plus"))).click();
        driver.findElement(By.xpath(obj.getProperty("four"))).click();
        driver.findElement(By.xpath(obj.getProperty("equalsto"))).click();
        Thread.sleep(4000);

        driver.findElement(By.xpath(("result"))).getAttribute("value");

        //String i = driver.findElement(By.name(obj.getProperty("result"))).getAttribute("value");
        //System.out.println(i);
        //System.out.println(obj.getProperty("eight") + " + " + obj.getProperty("four") + " = " + i);
        driver.findElement(By.xpath(obj.getProperty("result"))).clear();

这将在3…2…1…中编辑…请提供例外情况..您得到的例外情况是什么??在你的代码中,你在搜索一个-,我看不到。。。请输入正确的代码。问题在于“结果”定位器。我试过使用id、CSS选择器、名称等。。。通过对象文件进行搜索时,全部失败(仅适用于结果定位器)。异常=无法定位元素:{“方法”:“xpath”,“选择器”:“结果”}。但是,如果我直接在eclipse中使用任何定位器搜索元素,它就会工作!!!!!我在定位八个方面也遇到了类似的问题——我是通过id搜索的。当我直接在eclipse上搜索id时——它起作用了。必须更改为通过xpath进行搜索。是否有其他人在通过对象存储库文件查找元素时遇到问题?