So I'm having trouble formulating the correct syntax for selecting this element from a webpage. Here is what the path looks like on the Inspect Element Interface on Firefox
And here's what my current code looks like:
Element prices = doc.select("body[class =en page-type-search page-type-group-shelf og ress] " +
"div#wrap " +
"div#main-wrap " +
"div#jalapeno-template " +
"div[class=zone zone3 wgrid-10of12 wgrid-6of8 wgrid-4of4] " +
"section#shelf-page " +
"div#shelf-thumbs " +
"div.shelf-thumbs " +
"div.price-current " +
"span.product-price-analytics").first();
String priceOne = prices.attr("data-analytics-value");
And just to be incredibly clear, the attribute that I'm wanting is the 'data-analytics-value' because it gives an exact price.
I think that I have all the correct syntax so what am I doing wrong? When I run the program it gives me a nullPointerException. Any help is appreciated!
[Update] I changed princeOne to doc.toString() and its saying the the web browser is not running javascript and that JavaScript is required to view the walmart website, any work arounds?
After trying with no luck using Android's WebView, I accidentally found a solution in setting my userAgent, all I did was change the
Jsoup.connect(url).get();
line to
Jsoup.connect(url).userAgent("YOUR_USER_AGENT_HERE").get();
and it worked like a charm. Thanks for the reply anyway Fred!
Related
I'm looking for a way to set status on test steps and then on Scenarios that will be displayed in an HTML report using extent report. I'm using now Cucumber Java TestNG & Extent Reports and I set the status using Assertions:
Assert.fail(msg)
the issue for assert is that he throws Assertion Exceptions and I didn't found a way to suppress exceptions so I would like to set the status using extent like:
extentTest.log(Status.FAIL, msg);
The issue here is that you need to create the feature/scenario/test and I didn't found any documentation on this.
Hope you are looking for some methods which would print messages based on your requirement in HTML Reports generated by Extent. If so, then you would need to customize or write down method as per your need. I am attaching screen shot of HTML also a piece of code to give you vision how shall you proceed.
Like below method would add screen and message as well based on test failure. You can simply change testReport.get().fail to pass or warning based on your need.
public static synchronized void logFailed(String message) {
try {
testReport.get().fail("<details>" + "<summary>" + "<b>" + "<font color=" + "red>" + "Exception Occured : Click on the link to see message"
+ "</font>" + "</b >" + "</summary>" + "<br>" + "<h6>" + "<b>" + BasePage.returnLocator(message) + "</b>"+ "</h6>" + "</br>" + message.replaceAll(",", "<br>")+"</details>"+" \n");
addScreenShotsOnFailure();
}
catch(Exception e) {
}
}
im haveing a problem running a setline command
witch i want to set the line of a sign with..
it isn't doing anything
This is the part of the code that has the setline method in it it will run with a few other things when the player will give the input (the "if (SignEvent.isNumericArray(times))" is true for sure and the code is running i did check that )
if (SignEvent.isNumericArray(times)){
double uses = Double.parseDouble(times);
uses = uses -1;
sign.setLine(2 , uses + "/" + str[1] + parts[1]);
if (uses <= 0){
sign.setLine(0, ChatColor.STRIKETHROUGH + "StartPayment");
}
}
i did check a few things :
no errors in console or eclipse error list
object sign is type Sign imported from import org.bukkit.block.Sign
object sign is the right sign (checked by doing e.getPlayer().sendMessage(sign.getLine(0)); it worked..
no matter what the string is it isn't working
no matter where i put this line of code its not working
the this line is running
i just have no idea what could i do to fix it i tried a lot of things and im pretty sure the problem is in the
sign.setLine(2 , uses + "/" + str[1] + parts[1]); line
any one have any idea for what did i do wrong ?
Note: no matter where in this method i put the setline method or with what string/lineIndex ,it isn't doing anything
I think you have to execute sign.update(); after a modification to apply changes.
On Eclipse Luna, I need to programmatically build java projects and then retrieve the Problems View's records. I use the following code
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IResource resource = workspace.getRoot();
IMarker[] markers = resource.findMarkers(IMarker.MARKER, true, IResource.DEPTH_INFINITE);
for (IMarker m : markers) {
System.out.println("Id: " + m.getId());
System.out.println("Message: " + m.getAttribute(IMarker.MESSAGE));
System.out.println("Source ID: " + m.getAttribute(IMarker.SOURCE_ID));
System.out.println("Location: " + m.getAttribute(IMarker.LOCATION));
System.out.println("Line Number: " + m.getAttribute(IMarker.LINE_NUMBER));
System.out.println("Marker: " + m.getAttribute(IMarker.MARKER));
}
The message and line number are printed correctly. But IMarker.SOURCE_ID returns "JDT" and IMarker.LOCATION is always null.
Anybody knows how can I get the data shown as "Resource" and "Path" on the Problems View? I cannot create any custom Marker view using MarkerSupportView. I need to access the existing Problems View in a programmatic way. Thank you for any suggestion.
Got it. Use getResource() instead of getAttribute().
The markers API is pretty flexible, you should read the documentation.
Long story short, there will be other attributes that you're not looking at. Try calling getAttributes and dumping them out.
I am dealing with the log forging issue for the code :
log.error("Request: " + req.getRequestURL() + " raised " + exception);
This element’s value (req.getRequestURL()) flows through the code without being properly
sanitized or validated, and is eventually used in writing an audit log in handleError
I tried to remove the \n\r characters but with no success.
I have gone through different sites searching for the same but did not find the helpful content.
Can anyone please explain the solution for this or a small guide to fix it.
Thanks
Use ESAPI library to protect log forging attack. Refer to
http://www.jtmelton.com/2010/09/21/preventing-log-forging-in-java/ for code reference.
String clean = message.replace( '\n', '_' ).replace( '\r', '_' );
if ( ESAPI.securityConfiguration().getLogEncodingRequired() ) {
clean = ESAPI.encoder().encodeForHTML(message);
if (!message.equals(clean)) {
clean += " (Encoded)";
}
}
I'm currently sending an ajax request to a servlet and losing some information along the way. The parameter I am concerned about(losing data from) is the "comment" parameter. Below you can see my last 4 lines of ajax.
var params = "name=" + name + "&email=" + email + "&comment=" + comment + "&player_id=" + player_id;
xmlhttp.open("POST", 'comment', true);
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlhttp.send(params);
When I alert my params before the send and after the declaration they look like this:
name=Chris&email=email#gmail.com&comment=Hey, check this song out on groovershark http://grooveshark.com/#!/s/Here+feat+Soulive/2YDJIw?src=5&player_id=4
However in my servlet if I do a print line for the comment parameter right after getting it I get this output:
Hey, check this song out on groovershark http://grooveshark.com/#!/s/Here feat Soulive/2YDJIw?src=5
The problem is the "+" marks disappear somewhere along the request from ajax to the container and I have no idea why. I have narrowed it down to this problem area finally b/c I actually did not notice this until all the way in the database connection with the help of another stack overflow member. So if anyone could let me know what I can do to get my "+" characters back I would really really appreciate! Thank you so much!
You should encode your params prior to send them, like this:
encodeURIComponent(params);
xmlhttp.send(params);
You should percent encode the params part of the URI:
http://en.wikipedia.org/wiki/Percent-encoding#Types_of_URI_characters
In this way + becomes %2B and can be interpreted correctly on the server side.
Check out the encodeURIComponent() function: http://www.w3schools.com/jsref/jsref_encodeuricomponent.asp