Web page Embedded in a webpage, interacting with Watir elements - frame

I am having problems accessing a text field on a web site. What code would I write to input data into the input field txtUser?

You have to explicitly say the text field is in a frame:
browser.frame(:name => "content").text_field(:name => "txtUser").set "Lorem Ipsum"

Related

TestCafe does not write in text input field

I'm using TestCafe for test automation of a web application based on the Wicket framework. I try to type text into a text input field ... well, actually it is a dropdown list, where a text input field appears, so that the user can search for certain codes. The HTML fragment is as follows:
HTML fragment
And here is the corresponding screenshot (text field above "001"):
Text input field with dropdown
The user can type some characters and the list below is automatically filtered (I did this manually):
Text input field with some text
My TestCafe test tries this:
.click( productcodeList )
.expect( productcodeInputField.visible ).ok()
.click( productcodeInputField )
.typeText( productcodeInputField, 'ABW' )
i.e.
Click on the drop down list.
Assume that the text input field is now visible (works fine).
Click on the text input field (this should not be necessary, since typeText() is supposed to do this anyway).
Type the text "ABW" into the text input field ==> This does not work.
I'm sure that my Selector works, since the assertion (expect) is successful and when I debug the test run after the second click (on the text input field), I see the following:
TestCafe screenshot
I.e. the cursor is directly on the text field, but somehow TestCafe cannot write the text into the field.
Some additional information: The Selector for the input field is created as follows:
productcodeInputField = Selector('span').withAttribute('class', /select2-dropdown.*/ ).child('span').withAttribute('class', /select2-search.*/ ).child('input').withAttribute('class', 'select2-search__field' );
More information: I'm using the same logic on the same page:
kurzbezeichnungField = Selector('input').withAttribute('name', /.*aeAbbreviation.*/);
...
await t.click( kurzbezeichnungField )
.typeText( kurzbezeichnungField, 'xxxWWW' )
and this works fine.
Node.js version: v10.16.3
Testcafe version: 1.5.0
This issue looks like a bug. However, I cannot say it precisely without an example that demonstrates the problem.
My team would really appreciate it if you share your project or sample to demonstrate the issue.
Please create a separate issue in the TestCafe github repository using the following template and provide as much additional information as possible.

Selecting element using webdriver (duplicate identifiers)

I have to look at an application which I can't use the normal selectors (like "id", "name", etc - this is a design flaw) but I do have a custom tag which has been applied to elements on the page:
test-tag='x'
and this is fine, I can interact with this using (simple script)
var tag = '[test-tag="x"]';
var selector = $(tag);
However, I have now found that some elements (notably textboxes) have a title and a box element - both have the same custom tag applied. Now the text box is an input type. Anyone know how I can change the above to target specifially input types?
try this:
'input[test-tag="x"]'
for the input box
Take a look at this as well:
https://www.w3schools.com/cssref/css_selectors.asp

FormBlock Server Control in Ektron

I am working in Ektron 8.6.
I have a FormBlock Server Control in my Template Page,It is having a DefualutFormID of a valid HTML form from workarea.The form in the workarea have got few form fields and their corresponding values.
While the template page is rendering I need to GET those form field values and re-set them with some other values.
In which Page –Cycle event I should do this coding?
I tried this code in Pre-Render Event,but I am unable to GET the value there,but I am able to set a value.
I tried SaveStateComplete event as well,no luck.
String s=FormBlock1.Fields["FirstName"].Value;
If(s=”some text”)
{
// Re-set as some other vale.
FormBlock1.Fields["FirstName"].Value=”Some other value”;
}
In which event I can write this piece of code?
Page_Load works fine for changing the value of a form field. The default behavior is for the Ektron server controls to load their data during Page_Init.
The real problem is how to get the default value. I tried every possible way I could find to get at the data defining an Ektron form (more specifically, a field's default value), and here's what I came up with. I'll admit, this is a bit of a hack, but it works.
var xml = XElement.Parse("<ekForm>" + cmsFormBlock.EkItem.Html + "</ekForm>");
var inputField = xml.Descendants("input").FirstOrDefault(i => i.Attribute("id").Value == "SampleTextField");
string defaultValue = inputField.Attribute("value").Value;
if (defaultValue == "The default value for this field is 42")
{
// do stuff here...
}
My FormBlock server control is defined on the ASPX side, nothing fancy:
<CMS:FormBlock runat="server" ID="cmsFormBlock" DynamicParameter="ekfrm"/>
And, of course, XElement requires the following using statement:
using System.Xml.Linq;
So basically, I wrap the HTML with a single root element so that it becomes valid XML. Ektron is pretty good about requiring content to be XHTML, so this should work. Naturally, this should be tested on a more complicated form before using this in production. I'd also recommend a healthy dose of defensive programming -- null checks, try/catch, etc.
Once it is parsed as XML, you can get the value property of the form field by getting the value attribute. For my sample form that I set up, the following was part of the form's HTML (EkItem.Html):
<input type="text" value="The default value for this field is 42" class="design_textfield" size="24" title="Sample Text Field" ektdesignns_name="SampleTextField" ektdesignns_caption="Sample Text Field" id="SampleTextField" ektdesignns_nodetype="element" name="SampleTextField" />

Not able to get tooltip text using Selenium WebDriver

I have 5 tooltips in page. Using WebDriver, I am trying to verify these tooltip text.
I am using following code sequentially to get the tooltip text of all 5 elements:
Actions builder = new Actions(WebDriver);
builder.ClickAndHold(Element1).Perform();
Console.WriteLine(Element1ToolTip.text);
builder.ClickAndHold(Element2).Perform();
Console.WriteLine(Element2ToolTip.text);
builder.ClickAndHold(Element3).Perform();
Console.WriteLine(Element3ToolTip.text);
The issue is I get only the tooltip text of first element printed in console.
Is it because I need to refresh or reset the builder?
It's really weird when I delete the code for 1st element , then I can get tooltip text of 2nd element. So, basically it is getting tooltip text only once in single execution.
Verify tool tip by comparing "title" attribute of the web element and your expected tool tip text.
Console.WriteLine(Element1.GetAttribute("title"));
Console.WriteLine(Element2.GetAttribute("title"));
Tool tip text for input elements would be the title attributes and for images, alt attribute would be the tool tip.This is the standard for HTML 4, so I am not sure if you need to do hover and all.
Console.WriteLine(InputElement1.GetAttribute("title"));
Console.WriteLine(ImageElement1.GetAttribute("alt"));
http://www.javascriptkit.com/howto/toolmsg.shtml
I think, it needs to release from element as:
builder.release(Element1).perform();
So, your code could be as below:
Actions builder = new Actions(WebDriver);
builder.ClickAndHold(Element1).Perform();
Console.WriteLine(Element1ToolTip.text);
builder.release(Element1).perform();
builder.ClickAndHold(Element2).Perform();
Console.WriteLine(Element2ToolTip.text);
builder.release(Element2).perform();
builder.ClickAndHold(Element3).Perform();
Console.WriteLine(Element3ToolTip.text);
builder.release(Element3).perform();
I am facing the same issue , i checked the view source page on running the test and it appears that the title attribute is displayed as data-original-title.Due to which it is unable to display the text.On replacing the title with data-original-title . I am able to obtain text.

Is there a way to add "alt text" to links in PDFs in Adobe Acrobat?

In Adobe Acrobat Pro, it's not that difficult to add links to a page, but I'm wondering if there's also a way to add "alt text" (sometimes called "title text") to links as well. In HTML, this would be done as such:
link
Then when the mouse is hovering over the link, the text appears as a little tooltip. Is there an equivalent for PDFs? And if so, how do you add it?
Actually PDF does support alternate text. It's part of Logical Structure documented PDF Reference 1.7 section 10.8.2 "Alternate Descriptions"
/Span << /Lang (en-us) /Alt (six-point star) >> BDC (✡) Tj EMC
In PDF syntax, Link annotations support a Contents entry to serve as an alternate description:
/Annots [
<<
/Type /Annot
/Subtype /Link
/Border [1 1 1]
/Dest [4 0 R /XYZ 0 0 null]
/Rect [ 50 50 80 60 ]
/Contents (Link)
>>
]
Quoting "PDF Reference - 6th edition - Adobe® Portable Document Format - Version 1.7 - November 2006" :
Contents text string (Optional) Text to be displayed for the annotation or, if this type of annotation does not display text, an alternate description of the annotation’s contents in human-readable form. In either case, this text is useful when extracting the document’s contents in support of accessibility to users with disabilities or for other purposes
And later on:
For all other annotation types (Link , Movie , Widget , PrinterMark , and TrapNet), the Contents entry provides an alternate representation of the annotation’s contents in human-readable form
This is displayed well with Sumatra PDF v3.1.2, when a border is present:
However this is not widely supported by other PDF readers.
The W3C, in its PDF Techniques for WCAG 2.0 recommend another ways to display alternative texts on links for accessibility purposes:
PDF11: Providing links and link text using the Link annotation and the /Link structure element in PDF documents
PDF13: Providing replacement text using the /Alt entry for links in PDF documents
No, it's not possible to add alt text to a link in a PDF. There's no provision for this in the PDF reference.
On a related note, links in PDFs and links in HTML documents are handled quite differently. A link in a PDF is actually a type of annotation, which sits on top of the page at specified co-ordinates, and has no technical relationship to the text or image in the document. Where as links in HTML documents bare a direct relationpship to the elements which they hyperlink.
Alt text, or alternate text, is not the same as title text. Title text is meta data intended for human consumption. Alt text is alternate text content upon media in case the media fails to load.
There is also a trick using an invisible form button that doesn't do anything but allows a small popup tooltip text to be added when the mouse hovers over it.
Officially, per PDF 1.7 as defined in ISO 32000-1 14.9.3 (see Adobe website for a free download of a document that is equivaent to the ISO standard for PDF 1.7), one would provide alternate text for an annotation - like for example a Link annotation - by adding a key "Contents" to its data structure and provide the alt text as a text string value for that key.
Unfortunately Acrobat does not seem to provide a user interface to add or edit this "Contents" text string for Link annotations, and even if it is present it will not be used for the tool tip. Instead the tool tip always seems to be the target of the Link annotation, at least if it points to a URL.
So on a visual level one could hack around this by adding some other invisible elements on top of the area of the Link annotation that have the desired behavior. Not a very nice hack, at least for my taste. In addition it does not help with accessibility of the PDF, as it introduces yet another stray object...
Facing the same problem I used the JS lib "pdf-lib" (https://pdf-lib.js.org/docs/api/classes/pdfdocument) to edit the content of the pdf file and add the missing attributes on annotations.
const pdfLib = require('pdf-lib');
const fs = require('fs');
function getNewMap(pdfDoc, str){
return pdfDoc.context.obj(
{
Alt: new pdfLib.PDFString(str),
Contents: new pdfLib.PDFString(str)
}).dict;
}
const pdfData = await fs.readFile('your-pdf-document.pdf');
const pdfDoc = await pdfLib.PDFDocument.load(pdfData);
pdfDoc.context.enumerateIndirectObjects().forEach(_o => {
const pdfRef = _o[0];
const pdfObject = _o[1];
if (typeof pdfObject?.lookup === "function"){
if (pdfObject.lookup(pdfLib.PDFName.of('Type'))?.encodedName === "/Annot"){
// We use the link URI to implement annotation "Alt" & "Contents" attributes
const annotLinkUri = pdfObject.lookup(pdfLib.PDFName.of('A')).get(pdfLib.PDFName.of('URI')).value;
const titleFromUri = annotLinkUri.replace(/(http:|)(^|\/\/)(.*?\/)/g, "").replace(/\//g, "").trim();
// We build the new map with "Alt" and "Contents" attributes and assign it to the "Annot" object dictionnary
const newMap = getNewMap(pdfDoc, titleFromUri);
const newdict = new Map([...pdfObject.dict, ...newMap]);
pdfObject.dict = newdict;
}
}
})
// We save the file
const pdfBytes = await pdfDoc.save();
await fs.promises.writeFile("your-pdf-document-accessible.pdf", pdfBytes);