I need to read some properties of a DOM object via the selenium Java API. I'll explain my requirement via an example.
Let's say first I would like to find the <g> element highlighted in the Chrome Developer Tools (as shown below). I can easily do so via the Selenium Java API with the following code.
WebElement gElement = driver.findElement(By.xpath("//*[#data-id='node_grp_0_id52UVV33EHE7']"));
Then I would like to read several properties of this <g> object via the Selenium Java API. So, I click on this <g> element in the Chrome Developer Tools and open the Properties view on the right hand side of the Chrome Developer Tools (as shown below) in order to find the path to various properties. After finding the paths, I now would like to read several of these properties (e.g. ariaChecked and __data__.label) via the Selenium Java API as shown below:
gElement.getAttribute("ariaChecked");
gElement.getAttribute("__data__.label");
Both the above mentioned lines of code returns null.
The following code also does not return the desired property values:
element.getCssValue("ariaChecked");
element.getCssValue("__data__.label");
Does anyone know how to read various properties of a DOM object (listed in the Properties view of the Chrome Developer Tools as shown below) via the selenium Java API?
Thanks in advance!
I've found a workaround to read a property of a web element via Java Script as shown below. Nested properties are also supported by this workaround:
public String getProperty(final String name) {
return getJavascriptExecutor().executeScript("return arguments[0]." + name + ";", webElement).toString();
}
The above method can be invoked as shown below:
String name = getProperty("name");
or
String label = getProperty("__data__.label"); // This is a nested property.
Related
I have a JMeter test that insert an input via an HTTP call to an asynchronous java-service and then collects an exposed metric on another java-service via a groovy script.
The script then saves the collected metric as a JMeter variable to be reviewed as a performance metric.
I would like to publish this value inside the JMeter -generated dashboard but I can't find a way to save this variable as a JMeter output.
Is there a way? seems JMeter is primarily aimed to test HTTP synchronous services but it's capable of doing such collection of data.
You can use variable(s) in custom graph definitions:
You can graph any sample_variable in CSV over time, you can customize your graphs by settings their properties in the user.properties file.
They must use the id prefix custom_:
jmeter.reportgenerator.graph.custom_<your_graph_name_id>.property.<your_option_name>
To specify that this graph is a customized one :
jmeter.reportgenerator.graph.custom_<your_graph_name_id>.classname=org.apache.jmeter.report.processor.graph.impl.CustomGraphConsumer
Here is an example of a custom graph configuration that graphs the variable ts-hit:
jmeter.reportgenerator.graph.custom_testGraph.classname=org.apache.jmeter.report.processor.graph.impl.CustomGraphConsumer
jmeter.reportgenerator.graph.custom_testGraph.title=Chunk Hit
jmeter.reportgenerator.graph.custom_testGraph.property.set_Y_Axis=Number of Hits
jmeter.reportgenerator.graph.custom_testGraph.set_X_Axis=Over Time
jmeter.reportgenerator.graph.custom_testGraph.property.set_granularity=60000
jmeter.reportgenerator.graph.custom_testGraph.property.set_Sample_Variable_Name=ts-hit
jmeter.reportgenerator.graph.custom_testGraph.property.set_Content_Message=Number of Hits :
Declare the JMeter Variable you're saving in the JSR223 script as a Sample Variable, in order to do this add the next line to user.properties file:
sample_variables=foo
Then you can configure your custom chart like:
jmeter.reportgenerator.graph.custom_testGraph.classname=org.apache.jmeter.report.processor.graph.impl.CustomGraphConsumer
jmeter.reportgenerator.graph.custom_testGraph.title=Your custom chart title
jmeter.reportgenerator.graph.custom_testGraph.property.set_Y_Axis=Your Y axis name
jmeter.reportgenerator.graph.custom_testGraph.set_X_Axis=Over Time
jmeter.reportgenerator.graph.custom_testGraph.property.set_granularity=60000
jmeter.reportgenerator.graph.custom_testGraph.property.set_Sample_Variable_Name=foo
jmeter.reportgenerator.graph.custom_testGraph.property.set_Content_Message=Your custom content message
replace foo with the actual JMeter Variable name of your choice and next time you generate HTML reporting dashboard you should see your variable values plotted over time
More information:
Reporting configuration
Apache JMeter Properties Customization Guide
I want to write Java API code using playframework! (I'm using the Eclipse IDE.)
What would a sample API look like for insertion and selection?
How do I assign URLs in a routes file?
This answer applies to version 3 of the Play framework.
Here is a sample route file configuration to show a page. In this example, you can visit http://yoursite.com/1 , which will call controllers.Application.show("1").
# Extract the page parameter from the path.
# i.e. http://myserver.com/index
GET /:page controllers.Application.show(page)
SELECTION
Here is the corresponding show method definition in the controllers.Application controller:
public Result show(String page) {
String content = Page.getContentOf(page);
response().setContentType("text/html");
return ok(content);
}
INSERTION
For insertion, check out the "Form submission and validation" and "Working with JSON" sections of the documentation. There are examples there; sorry for not adding them here, but these are more complicated for this short format.
Source, and more information: https://www.playframework.com/documentation/3.0.x/JavaRouting
I am writing an RFT script using java.
I wanted to know if there is any way in which we can write a java code in script for searching a particular string in the webpage and recognize that object and then click on it.
To find a test object dynamically, you can use the TestObject.find() method. If you have some object in your object map which is a parent object of the object to find (e.g. a document object), you can use this example:
TestObject[] found = document().find(atDescendant(".text", "your particular string"));
GuiTestObject yourLink = (GuiTestObject)found[0];
yourLink.click();
Alternatively you can get all links on the page and do something with them:
TestObject[] links = document().find(atDescendant(".class", "Html.A"));
for (TestObject link : links)
if (link.getProperty(".text").toString().equals("your string"))
((GuiTestObject)link).click();
You can find more information about the find method in this article on the IBM developerWorks page.
I am trying to generate QRDA1 using MDHT model and have stuck up with the setting of the sdtc:valueset attribute to a code or value tag. The QRDA spec example below shows sdtc:valueset:
CE code = DatatypesFactory.eINSTANCE.createCE();
code.setCode("247472004");
code.setDisplayName("Hives");
code.setCodeSystem("2.16.840.1.113883.6.96");
code.setCodeSystemName("SNOMED CT");
these tags are present in MDHT library but
code.setValueSet("{$QDMElementValueSetOID}");
is not present in mdht model.
How can I solve this problem?
the updated Runtime jars which contains the sdtc:value attribute for code and values set are located at the below link
http://sourceforge.net/projects/oht-modeling/files/Releases/
open the link and click on the Runtime which contains the updated jars files.
Since I don't know how it is called the name of the Friendly format of the Mime Types like for example:
image/bmp - > Bitmap
image/x-icon - > Icon
I would like to ask how I can retrieve that information in some kind of Map with Key->Value (I am using Java)
Or some library where I can get them from.
I am using apache tika and there with MimeTypes.forName("application/pdf").getDescription(); is not returning me anything.
Anyways I think this question is irrelevant for every programming language.
I've found one website where I can see them but it is made with Table and I cannot extract them so I can receive them in key->value type HERE
You could just scrape that page.
If you're using Firefox with Firebug or Chrome then paste the following Javascript into an eval window and run it.
(The right hand side panel in Firebug's Console tab, or in Chrome; Tools > Developer Tools and paste in Console tab)
jQuery('#mime-types-list tbody tr').each(function(i, tr){
var tds = jQuery(tr).children('td');
console.log("map.put(\"" + jQuery(tds[1]).text() + "\", \"" + jQuery(tds[0]).text() + "\");");
});
This will generate 684 entries, to copy 'n' paste, such as:
map.put("text/turtle", "Turtle (Terse RDF Triple Language)");
Just convert the string inside console.log to suit your syntax/format needs.