• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Testing with Selenium Webdriver: How to use Xpath from properties files ?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I am fairly new to java and selenium testing. I am trying to set the framework, where I can save all the xpaths in xpath.properties( like object repository) and use it in all scripts.

But, I am not sure how to use it in the scripts. Can anyone please guide me how to use these values.

Here is my sample code.

## xpath.properties
phonesystem=//a[@id='menu_topNav_Id:j_idt77:1:j_idt79']

## script code
Properties prop = new Properties();
FileInputStream ip = new FileInputStream("C:\\Automation\\workspace\\TestNG Project\\src\\Config\\Config.Properties");
prop.load(ip);
String phonesystem = prop.getProperty("phonesystem");
driver.findElement(By.xpath("phonesystem")).click();

When I run the script, I get following error.
org.openqa.selenium.InvalidSelectorException: The given selector "//a[@id='menu_topNav_Id:j_idt77:1:j_idt79']" is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: Unable to locate an element with the xpath expression "//a[@id='menu_topNav_Id:j_idt77:1:j_idt79']" because of the following error:
[Exception... "The expression cannot be converted to return the specified type." code: "0" nsresult: "0x805b0034 (TypeError)" location: "file:///C:/Users/upatil/AppData/Local/Temp/anonymous2337003882435725061webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js Line: 5696"]
Command duration or timeout: 18 milliseconds


I am sure I am doing it wrong somehow, can someone please help me ?
I will really appreciate if any could help me.
 
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic