Forum Discussion

coffee's avatar
coffee
Contributor
8 years ago

Clicking a span button

Hi,

 

I have a span button on the webpage with this code

 

 

<span class="ui-autocomplete-icon searchmode" id="Schedule-00-Row471b178a-49c2-499d-828e-f0cac7690899E-Icon"></span>

 

I use this Javascript code in TC to point to that span button 

 

 

Page = Sys.Browser('*').Page("www.myweb.com");
var button = page.QuerySelector("span.searchmode");

 

Var button successfully find that span button. 

 

But when I do this 

 

 

button.ClickButton();

or 

button.Click();

 

TC complains that 

TypeError
button.ClickButton is not a function

or 

TypeError
button.Click is not a function

wondering why TC cannot click that button :mansad: 

 

Thanks. 

 

3 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    If you use the whole name of the button instead of the variable, does the click work?  

    • coffee's avatar
      coffee
      Contributor

      Thanks Marsha_R.  

       

      Not sure if I understand your comment correctly. That one line of HTML is the one that creates that button.

      I just use QuerySelector() to grab the whole line and then apply Click().

       

      I use this method to Click() other buttons and it works, just this span button doesn't work :mansad: 

      • Marsha_R's avatar
        Marsha_R
        Champion Level 3

        You have

        Page = Sys.Browser('*').Page("www.myweb.com");
        var button = page.QuerySelector("span.searchmode");

        and

        button.ClickButton();
        
        or 
        
        button.Click();

         but what happens if you do this instead?

        Sys.Browser('*').Page(www.myweb.com).QuerySelector("span.searchmode").ClickButton()

         

        For troubleshooting, you want to take all the variables out and first see if you can actually click the button.  Then we can see how to plug the variables in.