This is a migrated thread and some comments may be shown as answers.

Issues finding an element and clicking it..

2 Answers 188 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Francisco
Top achievements
Rank 1
Francisco asked on 15 Feb 2017, 09:35 PM

I've always had issues with these two "Calc" buttons, even with Selenium. 

I'm using Test Studio and simple left click does not work. I selected to code the step, one method prints errors no click, the other no errors still no click.

By the way, both Calc pictures seen in screenshot attached, have the same code.

 

1) By Attributes | Result: Error when executing

        [CodedStep(@"Desktop command: Calc1yClick")]
        public void Calc1yClick()
        {
            // Desktop command: LeftClick on CalcButtonTag
            HtmlControl Calc1yClick = Manager.ActiveBrowser.Find.ByAttributes<HtmlControl>("div class=btn btn-sm btn-primary", "data-bind=click: $root.calc, disable: !$root.isCalcEnabled()", "div class=btn btn-sm btn-primary", "data-bind=click: $root.calc, disable: !$root.isCalcEnabled()", "TextContent=Calc");
            Calc1yClick.Click();
        }

 

1) By XPath | Result: Finishes with no errors, but does not click on Calc button

        [CodedStep(@"Desktop command: Calc1yClick")]
        public void Calc1yClick()
        {
            // Desktop command: LeftClick on Calc1yClick
            HtmlControl Calc1yClick = Manager.ActiveBrowser.Find.ByXPath<HtmlControl>("/html[1]/body[1]/section[1]/div[1]/ul[1]/li[1]/a[1]/button[1]");
            Calc1yClick.Click();
        }

 

Actual Code:

<div class="pull-right" data-bind="visible: $root.inputsEnabled()">
    <button class="btn btn-sm btn-primary" data-bind="click: $root.calc, disable: !$root.isCalcEnabled()">Calc</button>
</div>

 

CssSelector extrated from Inspect: 

#rorInputsdbf047fe-1781-4f71-8f62-71bea1699aa6 > form > div > div:nth-child(2) > div > button

 

XPath extracted from Inspect: 

//*[@id="rorInputsdbf047fe-1781-4f71-8f62-71bea1699aa6"]/form/div/div[2]/div/button

2 Answers, 1 is accepted

Sort by
0
Lei
Top achievements
Rank 1
answered on 16 Feb 2017, 09:19 AM

Regarding Calc1yClick btn issue, put a break point at HtmlControl Calc1yClick = Manager.ActiveBrowser.Find.ByAttributes<HtmlControl>... Then after this line executed, watch this element Calc1yClick to check whether code locate the exact correct element. I guess it would say null.

Try this find expression:

Manager.ActiveBrowser.Find.ByAttributes<HtmlButton>("class=~btn btn-sm btn-primary","innertext=~Calc");

Sometimes, code would have issue in clicking even when we find the correct element. Under this condition, please try to click on its parent nodes, in your case, is a div.

 

0
Elena
Telerik team
answered on 20 Feb 2017, 03:18 PM
Hi,

@Lei: Thanks for interfering into this forum thread! 

@Francisco: Please give this suggestion a try and share if further assistance will be required. Additionally to simulate real desktop click you could use the Desktop Manager Class as described in this article

Regards,
Elena Tsvetkova
Telerik by Progress
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Francisco
Top achievements
Rank 1
Answers by
Lei
Top achievements
Rank 1
Elena
Telerik team
Share this question
or