Even though it looks the same to you, the button probably has a slightly different object name on the other page. You might not be able to call it "x" all the way through the test. It might need to be Page1x and Page2x and you check for enabled separately for the two.
Thanks @AlexKaras @Marsha_R I tried giving two separate object name/xpaths but it is not working for me,in first page only it starts looking at both the objects and the script fails. It might be due to my lack of coding knowledge but I am not getting how should I use 2nd object name. Could you please tell me where should I put 2nd/disabled object/xpath in the below mentioned code. In the below mentioned code I am trying to get the row counts for all the pages.
function Test()
{
var TotalCount;
do
{
var RowCount = Aliases.browser.pageSapiensDecision.FindElements("xpath for Rows");
TotalCount = TotalCount+RowCount.length;
//Enabled Next button
var Next_Button = Aliases.browser.pageName.ObjectName;
Next_Button.click();
}while (Next_Button.Enabled == true)
Log.Message(TotalCount);
}
Hi,
> how should we verify that.
Alas, web developers and web technologies are extremely ingenious these days in doing the same thing different ways. Even within one same web page.
To disable some web element, this element itself may be disabled. Or its parent. Or parent of the parent. Different class may be applied. Or some custom attribute or attribute's value and so on.
So you must either talk to developers and ask them how you can distinguish enabled element from disabled one or carefully inspect the element itself along with its parent(s) (if needed) in the Object Browser and figure out what makes this element to become disabled (state of some parent, class name, property, etc.) and use this finding in your code.
I tried checking in the TestComplete, when we are spying the object it is showing properties as Enabled = true even though on the screen the element is disabled.
className is slightly different for both, enabled element like class = "ui-button" and for disabled like class = "ui-button disabled"
Hi,
> enabled element like class = "ui-button" and for disabled like class = "ui-button disabled"
And this is the key for your case.
To distinguish between enabled and disabled button you must check if the value of the 'class' property contains 'disabled' substring.
@AlexKaras I have tried the below code but still it is not working. I might be doing something wrong but now sure what it is. Can you please have a look,
function Count()
{
var Row;
var TotalCount=0;
var hasNext = true;
do
{
Row = Aliases.browser.pageName.FindElements("//span[@class='className']");
TotalCount = TotalCount + Row.length;
if(Aliases.browser.pageName.FindElement("//a[((contains(concat(' ',@class,' '),'ui-paginator-next ')) and not(contains(concat(' ',@class,' '),' ui-state-disabled')))]").Exists)
{
var Next_Button = Aliases.browser.pageName.FindElement("//a[((contains(concat(' ',@class,' '),'ui-paginator-next ')) and not(contains(concat(' ',@class,' '),' ui-state-disabled')))]");
Next_Button.click();
}
else
{
hasNext = false;
}
}while (hasNext=true)
Log.Message(TotalCount);
}
Hi,
> still it is not working.
What exactly does not work?
Assuming that XPath-es are correct, I think that condition is missed for the Next_Button.
I would expect something like this:
...
var Next_Button = Aliases.browser.pageName.FindElement("//a[((contains(concat(' ',@class,' '),'ui-paginator-next ')) and not(contains(concat(' ',@class,' '),' ui-state-disabled')))]");
if (Next_Buton.Exists)
Next_Button.click();
else
hasNext = false;
...
@AlexKaras The script fails as at the last page where the button is disabled also the TestComplete looks for the below object. It doesn't go inside else block
var Next_Button = Aliases.browser.pageName.FindElement("//a[((contains(concat(' ',@class,' '),'ui-paginator-next ')) and not(contains(concat(' ',@class,' '),' ui-state-disabled')))]");
Hi,
> at the last page where the button is disabled
The button that becomes disabled is Next_Button, isn't it?
If it is, have you tried my suggestion? Does it help?
The button is same which got disabled but the property is changed when it was enabled the property was class = "ui-button" and when it got disabled the property is updated as class = "ui-button disabled".
I tried your suggestion but the output was same.
Next_button has a property of enabled object.
If I need to consider these two properties separately then how should I put the same in the code. I tried considering two objects one for enabled button other for disabled button but as both the present in different pages. The script fails as TestComplete starts looking for both objects together in the same flow.
Subject | Author | Latest Post |
---|---|---|