I need to verify that a specific string of text is present on webpage and check the number of occurences in LeanFT. I have tried code below to verify if text is present:
browser = BrowserFactory.launch(BrowserType.CHROME);
browser.getVisibleText().contains("Success");
I don't think getVisibleText on Browser is the best fit for the problem you're facing. AFAIK getVisibleText uses OCR and not the application's underlying technology.
A better way, I think, would be to identify the Web.Element that contains "Success". If you don't want to bother getting the specific element you can use the Page's text property.
I'm not familiar with LeanFT's Java SDK but in JavaScript it would be written like this:
expect(browser.$(Web.Page({})).text()).toContain("Success");
Edit: according to comments (thanks #Adelin), the Java equivalent is:
browser.getPage().getText().contains("Success");
Related
Let me just start by saying that this is a soft question.
I am rather new to application development, and thus why I'm asking a question without presenting you with any actual code. I know the basics of Java coding, and I was wondering if anyone could enlighten me on the following topic:
Say I have an external website, Craigslist, or some other site that allows me to search through products/services/results manually by typing a query into a searchbox somewhere on the page. The trouble is, that there is no API for this site for me to use.
However I do know that http://sfbay.craigslist.org/search/sss?query=QUERYHERE&sort=rel points me to a list of results, where QUERYHERE is replaced by what I'm looking for.
What I'm wondering here is: is it possible to store these results in an Array (or List or some form of Collection) in Java?
Is there perhaps some library or external tool that can allow me to specify a query to search for, have it paste it in to a search-link, perform the search, and fill an Array with the results?
Or is what I am describing impossible without an API?
This depends, if the query website accepts returning the result as XML or JSON (usually with a .xml or .json at the end of url) you can parse it easily with DOM for XML on Java or download and use the JSONLibrary to parse a JSON.
Otherwise you will receive a HTML that is the page that a user would see in a browser, then you can try parse it as a XML but you will have a lot of work to map all fields in the HTML to get the list as you want.
I am using mentions input jquery for my text area for mentioning names like facebook.
When I try to edit the mentioned text, already mentioned name changes to plaintext. How can I handle this?
Actually there is no such option, jQuery is a JavaScript Library, which you can implement for your own usage.
You cannot just ask jQuery to do your own work. You need to code it out!
When Facebook uses this feature, they actually try to use it like [userId:userName] which would be changed back to the Name and the Link to their profile.
I would ask you to do the same, when a user edit the names, replace that text fully. Don't just append it, just replace it as a whole. This way, the plaintext wouldn't be written and the mentionsId would have the new Name mentioned inside it.
Is it possible to edit browser's text field using java? Currently I'm using Jsoup to gather some information about websites so I'm looking for some more options.Could JSoup to this? Thank you!
I don't see how JSoup would help here. JSoup is just a way to parse html. You could use it to write out some html that has a text field in it with an input tag that has a value attribute on it. Then when you render the file in a browser, the page would have that value. But since you haven't given us very much information, I'm not sure if this is exactly what you want to do or completely different from what you want to do.
This is probably the last thing you'd want to do (not the first), but you could set the values of a text field using Java's Robot class.
I'm writing a Java application which parses links from html & uses them to request their content. The area of url encoding when we have no idea of the "intent" of the url author is very thorny. For example when to use %20 or + is a complex issue: (%20 vs +), a browser would perform this encoding for a url containing an un-encoded space.
There are many other situations in which a browser would change the content of a parsed url before requesting a page, for example:
http://www.Example.com/รพ
... when parsed & requested by a browser becomes ...
http://www.Example.com/%C3%BE
.. and...
http://www.Example.com/&
... when parsed & requested by a browser becomes ...
http://www.Example.com/&
So my question is, instead of re-inventing the wheel again is there perhaps a Java library I haven't found to do this job? Failing that can anyone point me towards a reference implementation in a common browsers source? or perhaps pseudo code? Failing that, any recommendations on approach welcome!
Thanks,
Jon
HtmlUnit can certainly pick URLs out of HTML and resolve them (and much more).
I don't know whether it handles your corner cases, though. I would imagine it will handle the second, since that is a normal, if slightly funny-looking, use of HTML and a URL. I don't know what it will do with the second, in which an invalid URL is encoded in HTML.
I also know that if you find that HTMLUnit does something differently to how real browsers do it, write a JUnit test case to prove it, and file a bug report, then its maintainers will happily fix it with great alacrity.
How about using java.net.URLEncoder.encode() & java.net.URLDecoder.decode().
So i'm trying to capture a certian section of a getQueryString(). I know I could try and go through and parse the string to get the certain section I wanted but was hoping to just be able to grab the piece I need.
Here is my query result:
N=0&Ntk=General&Ntt=info&Nty=1&D=info&Ntx=mode+matchallpartial&Dx=mode+matchall
I'm looking just to capture this part: Ntt=info
The =info part will change to whatever the search requested was.
I have gone through a lot of the API request function and haven't found anything that works for me.
Am I just going to have to parse it?
Use ServletRequest.getParameter
req.getParameter('Ntt');
It will return null if the parameter isn't set.