To find element is present or not
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To find element is present or not
I want to verify the element is not available in the page.
If I use findelement it throws error and if I use waitelement it will return the object.
Using find element == page. Findelement ("xpath")
It throws error as unable to find the object
Using wait element it returns true but for my verification the element is not there so it need to fail.
Here what i need is I don't get any error in log file what method I can use here
Any other methods to use
- Labels:
-
Script Tests
-
Test Results
-
Test Run
-
Variables
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think WaitElement should be the right method for your case.
It will return a stub object that has only the Exists attribute and its set to false by default.
https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/page/waitelement-meth...
If this still does return Exists == true then your object probably exists but is not visible.
What you can try is to check for exists and if its true you need to verify that it is not visible.
Or you have to specify your xpath so it will not find the element when its not visible.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@DanNadi have already tried waitelement it returns object only so the is not equal to
Refer below code
Var element=page.WaitElement("xpath", 2000)
If(element.Exists)
Log. Error
Else
Log. Message
It returns objects is there and prints the message
And also tried
If(element.Visible==true)
Log. Error
Else
Log. Message
Here also am getting message only
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Using the Object Browser and enable "Show invisible objects",
Is your UI object appearing in the Object Browser? Your UI object may Exists, but it's property value Visibility is set to False.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are you able to post an image similar to this, which shows the Object Browser and Properties for your UI object?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi.
To find if an element is present or not I use this script :
function get(page, value, presence = true, scroll = true) {
const pageElement = utils.getPage(page);
Options.Run.Timeout = 50;
optimisation.stopLog();
const elementHTML = pageElement.FindElement(value);
optimisation.startLog();
Options.Run.Timeout = 4000;
if(presence && elementHTML.Exists) {
elementHTML.scrollIntoView(scroll);
Log.Message("On a trouvé l'élément :" + value);
return true;
}else if(!presence && !elementHTML.Exists) {
Log.Message("On a pas trouvé: " + value);
return true;
}else{
Log.Error(`On a ${presence ? "pas " : ""}trouvé: ${value}`);
return false;
}
}
stopLog and startLog are important here, because when TC didn't find the object, it return an error. But this error is expected if we want to not find the object. (in my case, I don't want to log this error).
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
