Forum Discussion

MarcusBengtsson's avatar
MarcusBengtsson
Frequent Contributor
2 years ago

Selecting checkbox that changes name every run

Hello! I am trying to make the automation click on the checkbox but every run the xpath id for it is different (the red marked). I tried to use wildcard here but it doesnt work as id hope for. 

 

 

 

Anyone got an idea on how to fix this?

 

9 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    From what I remember, you can't use wildcards in XPath e.g. [@id='grid*'] but you should be able to use contains() or substring() - if you search for "javascript xpath contains" on the internet, you'll get plenty of results.

    • MarcusBengtsson's avatar
      MarcusBengtsson
      Frequent Contributor

      Hii, is there anything I could use from here? There are 2 different checkboxes I need to fill in, one from parameter and one from monitoring configuration. The first one is doing fine, but when it comes to the monitoring configuration its not working since it changes name ๐Ÿ˜ž

       

       

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Are you able to use the table cell, row and column values? What does the Object Spy tool show?

    • MarcusBengtsson's avatar
      MarcusBengtsson
      Frequent Contributor

      I got this reply from developer when i asked if they could set a static id to make it easier for the test:

       

      "Thatโ€™s correct, the grid id gets generated at run time because Ids needs to be unique.

       

      If we put some type of prefix before random Ids, would that help?

      e.g. MonConfGridxxxxxx"

       

      but I guess that would not solve that i still cannot use "MonConfGrid*" wildcard during xpath ๐Ÿ˜ž

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Here's a few examples of using XPath to highlight the control not using full id name,

    function test1()
    {
        // URL https://www.w3schools.com/html/tryit.asp?filename=tryhtml_id_css
        var page = Aliases.browser.Page("https://www.w3schools.com/html/tryit.asp?filename=tryhtml_id_css").FindElement("#iframeResult");
        var item = page.FindElement("//*[@id='myHeader']");
        Sys.HighlightObject(item);
        var item = page.FindElement("//*[@id[starts-with(., 'my') and string-length() > 3]]");
        Sys.HighlightObject(item);
        var item = page.FindElement("//*[starts-with(@id, 'my')]")
        Sys.HighlightObject(item);
    }

     

    • MarcusBengtsson's avatar
      MarcusBengtsson
      Frequent Contributor

      Hmm thank you for the reply and help I will try to figure something out for the keyword tests out from this ๐Ÿ˜ฎ