torus
2 years agoContributor
Web testing - Switch between using FindElement + Xpath to grab objects and using NameMap objects
Is there a way to use the 'FindElement' method for a NameMapping object? I thought (was hoping) the below code would work, but it does not. I read the 'FindElement' documentation and it says the FindElement is a method all Web test objects have.
The things in the NameMapping tree are web test object (I think). I don't know where I am going wrong.
I see the tableCell object has a 'firstChild' attribute. However, I don't want to use this. I only know how to identify the checkbox via the xpath ... I would like to use the xpath to find this sub-element.
function testFindElementMethod()
{
// Table_Row1_Col_HasAccess xpath-selector = //table[@id='s-table']//tbody//tr[not(contains(@class,'filter-row'))][1]/td[9]
var tableCell = Aliases.WebBrowser.OQM_Users_Page.Table_Row1_Col_HasAccess;
// If add 'tableCell' to my Watch list, i can see that this object did store it's findElement selector in the name attribute:
// tableCell's Name attribute: "FindElement(\"xpath=//table[@id='s-table']//tbody//tr[not(contains(@class,'filter-row'))][1]/td[3]\")"
// However, the below line of code does not find the child (grandchild) checkbox element like I think it would.
var child3 = tableCell.FindElement("//input[contain(@type,'checkbox')]");
}
You can use FindElement method on a mapped object. Not sure if this is a good example,
function TestX() { // URL: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_html_nested_table // Aliases.frameIframeresult = Sys.Browser("chrome").Page("https://www.w3schools.com/howto/tryit.asp?filename=tryhow_html_nested_table").Panel("container").Panel("iframecontainer").Panel("iframe").Panel("iframewrapper").Frame("iframeResult") var frame = Aliases.frameIframeresult; var table1 = frame.FindElement("/html/body/table"); Sys.HighlightObject(table1); var table2 = table1.FindElement("//*/td[2]/table"); Sys.HighlightObject(table2); var cells = table2.FindElements("//*/td[2]/table/tbody/tr"); for (var i = 0; i < cells.length; i++) { Sys.HighlightObject(cells[i]); } }