inspect text not showing in dev tools - java

I am trying to automate text field using selenium, when I try to inspect the object its not showing in dev tools
-text fields-
Industry : CGS-AGRIBUSINESS,
Client NAME : AB VOLVO
text name(Industry) I can see in dev tools but the text value not visible(CGS-AGRIBUSINESS), I want to verify the text ex : AB VOLVO, whether it is present or not
enter image description here

Open your Chrome devtools, and navigate to a tab called Properties. See the screenshot below.
In that tab, see if there is a property called value. I think you will be able to see the text that you want to verify CGS-AGRIBUSINESS in that value.
Now to retrieve the text from the value attribute, just use the getAttribute method to get the attribute value.
Here is a rough syntax
driver.findElement(your_xpath_or_any_locator_here).getAttribute('value')
This has already been explained in this SO question.

Related

Eclipse : Is it possible to open one resource in two different editors as per requirement?

In my current project, there is a situation where we have one file let's say "File1.cfg" in project explorer. There is a default editor "Editor 1" registered using "*.editors" extension.
Requirement Function:
When a user double click on the File1.cfg, it should be opened with an "Editor 1" by default and all the time.
There is one more option provided in Toolbar which will be used to open "Editor 2". And this editor should use the resource "File1.cfg" and display the contents as per the UI.
How can this be achieved in the Eclipse?
A plug-in can specify the editor id to be used when opening an editor. See IWorkbenchPage.openEditor and IDE.openEditor.
Normally these APIs check for an editor (of any id) already being open on the file. If you want to force the editor with the given id to open regardless you need to use the IWorkbenchPage method:
IEditorPart openEditor(IEditorInput input, String editorId, boolean activate,
int matchFlags)
with the matchFlags value set to:
IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT
to only match an existing editor with the same id and input.

Selenium WebDriver Java. Unable to locate image

I'm trying to determine the element of the below image/icon.
Note: Other icons have the same //div[#class='infor-collapsed-icon-img' so i think i need another unique id to identify the exact element below. ID is dynamic btw
Here's what i tried so far by using xpath:
1.) //div[#class='infor-collapsed-icon-img' and contains(#title,'Print Manager - Print Manager webpart allows the Lawson workspace user to contextually filter the print files of batch Jobs.')]
2.) //img[#title='Print Manager - Print Manager webpart allows the Lawson workspace user to contextually filter the print files of batch Jobs.']
3.) //img[contains(#title,'Print Manager - Print Manager webpart allows the Lawson workspace user to contextually filter the print files of batch Jobs.')]
Any thoughts on this? thanks
Try this XPath. First select the div and then the img tag within it.
"//div[#class='infor-collapsed-icon-img']/img"
EDIT 1: If you want to fetch a specific image then you can fetch it by using the id attribute of the tag
"//img[#id='img_WebPartTitlect100_m_g_f26cdbcd_963c_46f4_94b1_c6a4fd7a9aab']"
Or by the index of its occurrence in sequence. (I'd recommend this one since it is much cleaner)
"(//div[#class='infor-collapsed-icon-img']/img)[1]"
EDIT 2: Try using contains() to match the text partially.
"//div[#class='infor-collapsed-icon-img']/img[contains(#title, 'Print Manager')]"
If you want to 1st image
//div[#class='infor-collapsed-icon-img']/img[1]
If you want to 2nd image
//div[#class='infor-collapsed-icon-img']/img[2]
Hope it will help you :)
You can find the element by ID
driver.findElement(By.id("imgId"));
Id's are unique, so you will have the specific element.
In your case img_WebPartTitlect100..., look for the id attribute after src attribute.
Edit :
You can also try
driver.findElement(By.cssSelector("[title*='Print Manager']"));
That will give you element with has title which contains "Print Manager".
Try this:
driver.findElement(By.Xpath("//img[#src='your source']");
Try this:
//table[#class='infor-collapsed-pane']/tr[1]/td//img

Console. Write text with "link" to class/line

Whenever you display a stack trace, you can get a "url-like" text which if you click it opens the appropriate class at the appropriate line.
Is there a possibility to output a text in a way that the console recognizes it and make it clickable like that?
But how would you format the output so it would recognize it as a "link" ?
You can't and you don't.
AndroidStudio supports that feature. You just need to call
exception.printStackTrace() and you should be able to click it in the console tab of IDE.
You will see something like
java.lang.Exception
at whatever.Test.main(Test.java:22)
The text inside the bracket will be highlighted and you can click it.
Based on #JEeemy's answer I managed to do this
public static void printLinkToThisLine() {
System.out.println(Thread.currentThread().getStackTrace()[3]);
}
I works for me ...
I don't know if you're using Eclipse, but the Eclipse console parses based on a pattern: FileName.java:lineNumber.
MyFile.java:3
Would link you to the 3rd line of whatever class you specified as MyFile.
You could use:
.getClass().getName()
to the the name of the file programmatically.

How to get current browser in RFT test script

I have my webpage opened using RFT. In that page, I have a link I want to click.
For that I am using
objMap.ClickTabLink(objMap.document_eBenefitsHome(), "Upload Documentation", "Upload Documentation");
The current page link name is "Upload Documentation"
I know that objMap.document_eBenefitsHome() takes it back to the initial page, what can I use in that place which uses the "current page opened" ?
Many thanks in advance.
There are some alternatives that could solve your problem:
Open the Test Object Map; select from the map the object that represents the document document_eBenefitsHome; modify the .url property using regular expression, so that the URLs of the two pages you cited in your question match the regex.
Find dinamically the document object using the find method. Once the page containing the link you want to click was fully loaded, try to use this code to find the document: find(atDescendant(".class", "Html.HtmlDocument"), false). The false boolean value allow the find method to search also among object that are not previously recorded.

watermark in birt based on parameter

I have a invoice for which I want to show in preview mode with a watermark. I have integrated the report with my web application (Spring MVC).
Any solution?
EDIT: I want to pick a value from a dataset (Table: invoiceheader), and use that value to decide whether to show /not show the watermark. I am unable to pick that value from Birt script. Can you please please guide..
Sorry .. the customer asked for a different way of identifying the fact rather that from passing the parameter.
Thanks
You need to declare a report parameter in the .rptdesign of the invoice. For example we name it "useWatermark", and we set the datatype to boolean and a default value to true.
Select the report root in the outline view of the designer -> script tab -> beforeFactory
if (!params["useWatermark"].value){
reportContext.getDesignHandle().findMasterPage("Simple MasterPage").setProperty("backgroundImage", "");
}
This script removes the watermark if the parameter is set to false. By default, the master page is named "Simple Masterpage" but if you have renamed it or if there are multiple masterPages defined in the report you should adjust the script consequently.
EDIT: if we need to extract the information from a dataset, then we can't make use of the masterPage, we have to use a grid instead.
Create a grid with one cell, and drop all the content of your page into it
Set your watermark as background-image of the grid
Create a report variable "useWatermark" in the "Outline/variables" branch (see picture below), set default value to true/false as you like
Select dataset invoiceHeader -> script tab -> onFetch, and affect the variable from a boolean dataset column, or from any expression returning true/false:
vars["useWatermark"]=row["myBooleanDatasetColumn"];
This dataset must be used somewhere in the report body, otherwise it won't be triggered and the variable won't be initialized
Select the grid -> script tab -> onRender
if (!vars["useWatermark"]){
this.getStyle().backgroundImage="";
}

Categories