Unable to retreive xpath from object repository during script

Hello,

I am trying to use Selenium in one of my scripts to select more then one menu item at a time before clicking the run button. That part is working, but I want to pull the xpath from the object repository so that if it needs to change I don’t need to update the script. The problem is, I am getting a null. I should be able to include information here. Please let me know if the answer is apparent to anyone here thanks! See below.

Object -

I have been entering the xpath under Selection Method - XPath but just in case it needed to be an attribute I also added it as an attribute. In both locations the xpath = //*[contains(@id, ‘Load Supplier Master Data’)] and within WebUI it works just fine.

Forum post where I initially found what the solution should be -

Code (The commented out line works fine with the xpath hard coded) -

WebDriver driver = DriverFactory.getWebDriver()

Actions actions = new Actions(DriverFactory.getWebDriver())

String eLoadSupplierMasterData = findTestObject(‘Object Repository/Engine Execution Log/Engine Execution Request - Processes To Execute/Processes to Execute - Load Supplier Master Data’)
.findProperty(“xpath”)

actions.keyDown(Keys.LEFT_CONTROL)
.click(driver.findElement(By.xpath(eLoadSupplierMasterData)))
//.click(driver.findElement(By.xpath(“//*[contains(@id, ‘Load Supplier Master Data’)]”)))
.keyUp(Keys.LEFT_CONTROL)
.build()
.perform();

Updating this, found another thread on the forum. Link below. The answer appears to be that I need to use expression language which I don’t have a lot of experience with but it seems to be working now.

Updated code -

WebDriver driver = DriverFactory.getWebDriver();

Actions actions = new Actions(DriverFactory.getWebDriver());

TestObject eLoadSupplierMasterData = findTestObject(‘Object Repository/Engine Execution Log/Engine Execution Request - Processes To Execute/Processes to Execute - Load Supplier Master Data’);

actions.keyDown(Keys.LEFT_CONTROL)
.click(driver.findElement(By.xpath(“${eLoadSupplierMasterData.findPropertyValue(‘xpath’)}”)))
.keyUp(Keys.LEFT_CONTROL)
.build()
.perform();

1 Like