Home » Test Studio tricks

Test Studio tricks

  • Test Studio coded step to get href value of a link using xpath.
    HtmlAnchor urlElement = ActiveBrowser.Find.ByXPath<HtmlAnchor>(“yourXpathHere”)   // You will have complete access of element in HtmlAnchor ‘urlElement’
    string url = urlElement.Attributes.Single(a=>a.Name==”href”).Value.Trim(); // control will find href attribute and place it in string url.

Same way you can get any value of a link by specifying the attribute name.

  • Test Studio coded step to select radio button using xpath.
    HtmlInputRadioButton placeOption = ActiveBrowser.Find.ByXPath<HtmlInputRadioButton>(YourRelativeXpath);

    Relative Xpath. To make your code more generic you should use relative xpath. For example, say  you have 4 radio buttons with place names Bangalore, Mumbai, Bijapur and Indi .Let us assume, the above texts of radio buttons is in span tag, so we have to first identify the text by using //span[text()=”Bijapur”] and go to its parent by //span[text()=”Bijapur”]/../.. Then finally find the input tag where radio button lies //span[text()=”Bijapur”]/../..//inputThis way we made xpath dynamic and we can just change the name of place in the xpath to select that radio button. Now you can use for loop to check all the options by passing place name one by one.

  • Test Studio Simulating Real Click coded step

          Manager.Desktop.KeyBoard.TypeText(“YourTextGoesHere”, 50, 100, true);