Need your help figuring out to write the xpath for an object located within an iframe, in a groovy script
Elements are to be extracted from a web table embedded within an iframe. screen is as below
I want to be able to get the Plan, Member, Coverage info for the two rows 01 and 02 we see on the screen(there could be more too if more plans are there)
I was trying to read all elements into an ArrayList and then was going to try writing it out to my results spreadsheet.
using the for loop so I can pass an index to identify which row I want the data from like below
for (def index = 2; index <= planCount; index++) {
plan = WebUI.getText(findTestObject(By.xpath(“//iframe[@name=‘_iframe-popupWin’]//div[@id=‘contentstart’]/div/table/tbody/tr[index]/td[2]”)))
println("Plan: ") + plan
}
The object of the webtable I am trying to get to starts with //div[@id = ‘contentstart’… which is located within an iframe, the xpath to which is the preceding xpath - right after findTestObject. What would be the proper syntax to get to the object? Will appreciate any help I can get. Thanks!
Thanks for your replies. Trying to go through the doc you sent.
Code I am using is as below: Syntax for xpath with a parent iframe I am not able to figure out
for (def index = 2; index <= planCount; index++) {
plan = WebUI.getText(findTestObject(By.xpath("//div[@id='contentstart']/div/table/tbody/tr[index]/td[2]parent::div")))
println("Plan: ") + plan
}
It’s a long piece of code: Basically I am adding plans in the UI, which look like the screen 1 I sent earlier. It’s in a web table within an iframe. I need to get elements out from there and write it to my results spreadsheet. Can we even specify an xpath in groovy?
//SAVE Plan
WebUI.click(findTestObject('ePost GUI/pagePlan/input_Today_SAVE'))
WebUI.delay(1)
//Check for Alerts in Plan fields.
//If Alert encountered do not continue
if (!alertCaught ) {
if( dataValues_Plan.get( "AddPlan" ).equalsIgnoreCase( "true" ) && ++planCount < 4 ) {
//Skip to the next row in Plan sheet, to add another plan
rowPlan++
dataValues_Plan = WDSpreadsheet.ReadSpreadsheetRowAsMap( "Reports/" + xlsName, "Plan", rowPlan )
firstPlan = false
planCount++
}
else {
finishedAddingPlans = true
}
}
}
} //End of while loop for adding Plans
//Write results to PLAN sheet
if (!alertCaught) {
//Write results to PLAN sheet
for (def index = 2; index <= planCount; index++) {
WebUI.switchToFrame(findTestObject('ePost GUI/pagePlan/iframe_epostRx Pop-up__iframe-popupWin'), 5)
plan(i) = WebUI.getText(findTestObject("//div[@id='contentstart']/div/table/tbody/tr[index]/td[2]"))
println("Plan: ") + plan(i)
colNumber = WDSpreadsheet.FindSpreadsheetColumn( "Reports/" + xlsName, "Plan", 1, "PLAN_Plan" )
WDSpreadsheet.WriteToSpreadsheet( "Reports/" + xlsName, "Plan", colNumber, rowPlan--, Plan1 )
}
I want to specify an xpath in the script, as I am parameterising the indexes to be able iterate and read thru the web table. Hope you saw the screenshot of the web table whose elements I want to get. The number of rows it could contain will vary according to number of plans added. So I wanted to do a ‘for’ loop to iterate through the rows and get the text out of the web table elements using xpath to specify the location of the object within the web table.
so xpath somewhere in this for loop
for (def index = 2; index <= planCount; index++) {
WebUI.switchToFrame(findTestObject('ePost GUI/pagePlan/iframe_epostRx Pop-up__iframe-popupWin'), 5)
plan = WebUI.getText(findTestObject("//div[@id='contentstart']/div/table/tbody/tr[index]/td[2]"))
println("Plan: ") + plan
}
You want to make a Test Object with a XPath dynamically created you test case scrit.
Then
You should not use findTestObject() any more. The findTestObject() function looks into the Test Objects folder in the project directory to pick up an entry.