I wanted to create a hyperlink using Apache POI and Java for Selenium Webdriver automation testing. But the thing is, when i'm creating a hyperlink using this code :
File file=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
String screenshotLocation = "D:\\MyFolder\\Test Results\\Screenshots\\";
screenshotURL=screenshotLocation+datetimestamp+".png";
FileUtils.copyFile(file, new File(screenshotURL));
#SuppressWarnings("deprecation")
HSSFHyperlink link = (HSSFHyperlink)createHelper.createHyperlink(Hyperlink.LINK_FILE);
link.setAddress(screenshotURL);
hyperlinkList.add(link); // add all hyperlinks to an arraylist
createHyperlink and LINK_FILE are showing as deprecated. Is there any alternate way to create hyperlink without deprecation? ( I've tried with XSSF also, but getting the same deprecation.)
FYI: when i'm using selenium-server-standalone-2.47.1.jar and poi-bin-3.17-beta1-20170701 , it is showing only the deprecation, not any error. But when i'm using updated version, for example Selenium-java-2.48.2.jar and poi-bin-3.17-20170915, along with the deprecation, one error message is showing: LINK_FILE cannot be resolved or is not a field.
Please Help. Thanks in advance.
Hyperlink.LINK_FILE is replaced by HyperlinkType.FILE
and the createHyperlink function was replaced by a new Funtion with the Parameter if type HyperlinkType
From the javadoc:
Hyperlink createHyperlink(int type)
Deprecated. POI 3.15 beta 3. Use createHyperlink(HyperlinkType)
instead.
And
static int LINK_FILE
Deprecated. POI 3.15 beta 3. Use HyperlinkType.FILE instead.
Related
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.
I have a tapestry 5.4 project, and I want to override one element of the default core.properties file.
I tried to add to login_en.properties and login_hu.properties a new line (core-default-error-banner=...) but it do not override it.
Is there any way to overwrite it?
Thanks for the answers in advance.
If you intend to overwrite the header line of the Errors component, just specify your own message id in the page/component template like this:
<t:errors banner="message:your-translated-error-msg-id" />
To support other locales, just translate the built-in message catalog (property) files yourself: To have Tapestry use these new files, just put them in the corresponding package-named directory within your own app (for example, src/main/resources/org/apache/tapestry5/core.properties). More informtation can be found from Tapestry site.
I've updated to elasticsearch java library version 5.2.0.
In 2.x,
I was using SearchRequestBuilder.addField() in order to add a field to the search request. Nevertheless, It seems to be replaced. I've written the available methods intellisense is showing me. Which of them do I need to pick?
addDocValueField
addFieldDataField
addScriptField
addStoredField
storedFields
fields
SearchRequestBuilder.setNoFields is also removed. Which would be the alternative?
Currently, I'm calling scripts from Java using this code. Is there any more elegant way to call it in 5.x Java API?
Code:
return AggregationBuilders
.terms(this.getName())
.field(this.getName())
.script(new Script(
ScriptType.FILE,
"painless",
"year",
ImmutableMap.of("field", this.getName())
)
);
As you can see I setting field as script parameter. Nevertheless, I don't quite understand how to get it from script code.
Thanks.
When in doubt, go to the source
use setFetchSource(String[] includes, String[] excludes) instead
use setFetchSource(false) instead
if you need to execute this script for each document, you can use addScriptField()
I am trying to save a file using write.xslx (when saving with write.csv some row got shift in more columns so I am trying to save the file as xlsx directly).
If I type this command:
write.xlsx (old.data, file ="Documents/new.xlsx", sheetName="Sheet1",col.names=TRUE, row.names=TRUE, append=FALSE)
or
write.xlsx (old.data, "Documents/new.xlsx", sheetName="Sheet1",col.names=TRUE, row.names=TRUE, append=FALSE)
I get this error:
Error in .jnew("org/apache/poi/xssf/usermodel/XSSFWorkbook") :
Java Exception <no description because toString() failed>.jnew("org/apache/poi/xssf/usermodel/XSSFWorkbook")<S4 object of class "jobjRef">
Can anyone help me sort it out?
I don't think that this question can easily be answered. Is <working_directory>/Documents writeable to you? Can you create the file
write.xlsx ( data.frame( a = 1:10, row.names = letters[ 1:10 ] ), "Documents/new.xlsx", sheetName="Sheet1",col.names=TRUE, row.names=TRUE, append=FALSE)
If this works, but with old.data it doesn't you have to provide a reproducible example.
However, I experienced every here and again weird problems with the xlsx package. From my experience XLConnect is much more robust and bug-free:
library("XLConnect")
writeWorksheetToFile( "Documents/newxlsx", old.data, "Sheet1", header=TRUE, rownames = "rownames.header" )
write_xlsx() from the writexl package works great for me and is way faster! It also works fine with tibbles and does not have the annoying errors or resctrictions from the xlsxpackage. It is also completely written in C so no Java, Perl or Rtools are required.
For more info see https://ropensci.org/technotes/2017/09/08/writexl-release/
I just had this same problem. I think there might be a bug with openXL but I love working with it. So I open and close R and then change the wd, saved the file exactly where the wd was and then I run the exact same code again. It worked.
Today I had that problem after deployment.
At this moment I didn't need to change package and stick to xlsx
I updated dplyr, xlsx, and the one that did the trick was updating rjava.
Since it was a conflict with java and xlsx calls it, I gave it a shot.
Hope this work for you too
I am trying to display the result of a Mondrian query using JPivot. Many examples are showing how to use the tag library for JSP but I need to use the Java API, I looked at the documentation but I cannot understand how to use it to display the results in the table. Here is my code
Query query = connection.parseQuery(mdxQuery);
Result result = connection.execute(query);
result.print(new PrintWriter(System.out,true));
I would like to know if I can use the result object to build the jpivot table.
Thanks in advance!
First of all, using JPivot
is a pretty bad idea.
It was discontinued back in 2008.
There is a good project which is intended to replace the JPivot called Pivot4j. Despite it is currently under development (0.8 -> 0.9 version), Pivot4j can actually do the business.
However, if we're talking about your case:
result.print(new PrintWriter(System.out,true));
This string prints the HTML code with OLAP cube into your System.out.
You can write the HTML code in some output stream (like FileOuputStream), and then display it.
OutputStream out = new FileOutputStream("result.html");
result.print(new PrintWriter(out, true));
//then display this file in a browser
However, if you want to have the same interface as in JPivot, I don't think there is an easy way to do it without .jsp. In these case I strongly recommend you to try Pivot4j.
Good luck!