XPATH Input Tag Query - Katalon Studio - groovy

I wanted to read the text of "TestData.txt" from the below HTML Code. There is huge html code in the original page. Sharing the below content for reference. There are few more input tags on the top to the below mentioned HTML code.
Can you please correct the below step definition code ?
Step Definition
TestObject testObj5 = new TestObject().addProperty("xpath", ConditionType.EQUALS, "//input[#value='TestData.txt']??")
inq = WebUI.getText(testObj5)
HTML Code
<input type="file" name="file_attach_text" accept="text/html" value="TestData.txt" onkeypress="if(chkKey(event)){return false;}" id="attach_text" class="button" title="Opens a dialog box to select files">

You can select the element using the xpath with the name attribute and then get the value like this:
TestObject testObj5 = new TestObject().addProperty("xpath", ConditionType.EQUALS, "//input[#name='file_attach_text']")
inq = WebUI.getAttribute(testObj5, "value")

Related

Can not get siblings from the start of a query xpath

I have the following structure of the XML file:
<body>
<content>
<text type="header">Header 1</text>
</content>
<content>
<text type="text">Text 1</text>
</content>
</body>
I need to get the first one content tag and then using that content element get his content tag sibling in node.js with select function.
Node.js xpath npm package.
What I am trying to do is:
allDocumentString is a string representation of all the XML
file.
const headerContentTag = select('//content/text[#type = 'header']', allDocumentString);
const textContentTag = select('//following-sibling::content', headerContentTagString);
But it does not work.
I need to exactly get the first one content tag and then depending on that tag the last one.
I know I can get the second one tag just without the first one, but I need the first one.
Strictly speaking, what you need is :
var doc = new dom().parseFromString(xml)
var nodes = xpath.select("//body/content[1][./text[#type='header']]/following-sibling::content[last()]", doc)
We first look for the first content element, child of body and which contains a text element with a #header attribute. Then get we get his last following-sibling.

chameleon can not render deform form

I have used deform before with jinja engine but with chameleon i can not render my form
I pass the form to the view to be rendered
#view_config(route_name='home_cms',
renderer='../views/accounts.pt',
request_method='GET',
)
def home(self):
model = Bundle("ModelAccounts", xx.account_id,
xx.name, xx.state, xx.account_type)
cm_filters = xxx(self.request.db)
list_accounts = xxx.search(model=model)
return dict(list_accounts=list_accounts, filter_form=self.form.render())
in the view i add this line
<span tal:content="python:filter_form"></span>
and in the main function I add this line of code
deform.renderer.configure_zpt_renderer()
config.add_static_view('static_deform', 'deform:static')
You don't say specifically what you are getting, but from what I can see I think the issue you are facing is that your HTML form is getting escaped. If this is the case then change your template code in ../views/accounts.pt' to read:
<span tal:content="structure: filter_form"></span>
The "structure" keyword tells Chameleon to not escape the value. See http://chameleon.readthedocs.io/en/latest/reference.html#structure for more details

Visual Studio Coded UI: Select HTML Element by CSS Selector

I have run into a problem selecting an item within Microsoft's CodedUI framework. I have a page full of items that can be added/removed via selecting a checkbox. The checkboxes do not have unique id on them, and I am having trouble selecting other than the first item when looking for a particular Tag/class combination. Is there some trick to doing this that isn't immediately obvious.
There are a couple different options here:
1. You could select the object by selecting the item related to it
<div id="parent">
<label id="checkbox1234">MyCheckBox</label>
<input checked="false"></input>
</div>
... could be selected as:
HtmlDiv parent = new HtmlDiv(browserWindow);
parent.SearchProperties["innerText"] = "MyCheckBox";
HtmlCheckBox target = new HtmlCheckbox(parent);
target.SearchProperties["TagName"] = "INPUT";
return target;
or
HtmlLabel sibling = new HtmlLabel(browserWindow);
sibling.SearchProperties["id"] = "checkbox1234";
UITestControlCollection col = sibling.GetParent().GetChildren();
foreach (UITestControl control in col)
{
if (control.ControlType.ToString().Equals("HtmlCheckBox"))
{
return (HtmlCheckBox)control;
}
}
You can use these test utilities created by Gautam Goenka. They worked wonders for me as far as identifying the content of an object and using it for assertions. Still, if you don't have any meaningful way of identifying the objects based on content, this won't help you either. When all else fails, add some useful identifying properties to the HTML.

Alloy user interface (access a tag value)

I'm working with liferay portal 6.2. And I want to get the value of the text in a tag with alloy user interface.
exemple:
<div>
<p> Paragraph </p>
"value"
</div>
the desired result is: value
please help.
AlloyUI, being an extension of YUI3, uses get/set methods to access and manipulate the properties/attributes of the object (YUI3 Node / AlloyUI Node) that is returned when looking up elements from the page.
Some examples can be reviewed in this documentation as well as this documentation.
In general you'll need something unique (i.e. id, css class) to the div in order to fetch only that element. Once you have that element, divNode.get('text') will give you all of the text within the element. There is not a means to easily "skip" the paragraph contents within the div without the value being contained within some other markup. If you have control over the markup and can do this, that would be the best option. Otherwise you are left to using the replace function to strip out the paragraph contents from the text.
<script>
AUI().use('aui-base', function(A) {
var paragraphText = A.one('#myDiv>p').get('text');
var divText = A.one('#myDiv').get('text')
var onlyValue = divText.replace(paragraphText, "").trim()
console.log(onlyValue)
})
</script>

How can I know an object is not visible when any of parent object is not visible in an HTML page using java script?

Let say I have an text box in an HTML page as follows.
<DIV style = "display:none;">
<DIV style = "display:inline;">
<INPUT type = "text" style = "display:inline;">
</DIV>
</DIV>
In this case, the text box will not be visible to the user. How can I identify that text is not currently visible to the user.
Dont say that, I should travel up to the parent objects to find out if they are set to not visible. I have bunch of fields to be validated like this and this would reduce the application performance.
Is there any other way to find out as this object is not visible to the user?
Thanks in advance.
If you don't need it to be pure JavaScript I would suggest using jQuery. Using the :visible or :hidden selector will accomplish what you want:
if ( $('yourElement').is(":hidden") ) {
// The element is not visible
}
http://api.jquery.com/visible-selector/
http://api.jquery.com/hidden-selector/
If you need pure JavaScript and you don't want to travel up through every ancestor element, you could try checking the element's offsetWidth and offsetHeight. If the element is hidden because of an ancestor element, they should both be 0. Note: I've always used jQuery for this, so I don't know how reliable this is.
var yourElement = document.getElementById('yourElementsId');
if ( yourElement.offsetWidth == 0 && yourElement.offsetHeight == 0) {
// The element is not visible
}
https://developer.mozilla.org/en-US/docs/DOM/element.offsetWidth
https://developer.mozilla.org/en-US/docs/DOM/element.offsetHeight

Resources