I am working on selenium. I need to print an html link in the form of link/hyperlink.
For example:
System.out.println("https://www.google.co.in");
Reporter.log("https://www.google.co.in");
The above one prints the google link in text format but how can we print above one as in hyperlink/link format.
Is there any possible way to do this in selenium and also in java?
If you use System.out.println(...) then you can only output raw text to the standard output. Now, if you want to be able to click on links in this standard output it is very important to know, how you're viewing this output. The standard way would be on the console or, with logging, maybe in a log file.
Links have to be supported by whatever displays those links if you want to be able to click them; some consoles do that automatically but many don't. And the same goes for text viewers. This has nothing to do with Java or Selenium.
What may make sense is if you're creating HTML files and viewing those with Selenium; in that case, you could of course create links, as any HTML browser will support them. But I doubt that's what you're currently attempting. (Correct me if I'm wrong.)
Related
I realize this looks like a duplicate question, but it's not!(as far as I know, and I've searched a lot...) So for the last few days I've been trying to get the HTML content of my whatsapp web application but using the input stream reader provided by java seems to not give me the full html code. The URL I'm using is just https://web.whatsapp.com/, which I suppose could be a problem, but there aren't any personal URLs as far as I'm aware. However, in developer tools using the element inspector I can easily access and read the DOM elements I'm interested in. I'm wondering if there's a way I can get this source directly using java/perl/python.
I'm also looking to do this as a learning project, so preferably would like to stay away from tools such as jsoup and such. Thanks!
You can use selenium.webdriver in python. Something like:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get("https://web.whatsapp.com/")
html = browser.page_source
If you want to get your own whatsapp page, you should use selenium to log into the site before getting the page_source.
I'm looking a way to take a string (for example from a cell in excel, but it does not have to be from excel) and paste it in a form in a web page.
I prefer to do it in java but I didn't find anywhere how it's can be done in java.
Which way it's can be done?
Thanks.
Shaked.
You could consider using Selenium. It lets you pre-define a set of actions for a browser, including going to a certain page, fiddling with form fields, and submitting the form.
It is possible to program this with Java, and as you may know, you can also use Java to read from files on your computer.
Is it possible in java to read something that's on the screen into the program, such as a specific line on the screen? Say I need the program to get some numbers that are on a website and depending on the numbers it'll perform a specific task, is there a way to have the program scan and get input from a specific website?
Yes, there is a way.
For example using test framework Selenium Webdriver.
It has embedded Firefox driver.
So you only need to add this framework to your project, create an instance of Firefox driver, enter URL of your site, then using xPath/ID/CSS path, get values you need and process them.
To search for xPath use Firebug , load your site in FF, right click on the element, inspect in Firebug, right click on the element -> get xPath
Java can make Screenshots. If you use OCR text recognition you can then extract texts.
However usually you access the sources directly (for example use java to receive a html page, instead of reading text from screen output of a browser).
I have a form with 100's of fields along with radio and check-box. What will be the best way to create PDF from it. Here is the link to my form 'http://182.71.22.42/ccs/'. I have used 'JSPDF' library but it just prints text only in PDF not any input field. I have also tried 'TCPDF' but I don't know how to show check-box and radio buttons and also I have to do css for 'TCPDF' also. Because TCPDF does not pick any HTML form css..
Please help me with this. Thanks in advance.
I like pdftk (PDF Tool Kit). It's fairly easy to use. There is a GUI, but there's also a command line tool -- which is obviously what you'll want to use. You'll install the pdftk program on your server, and run it from your PHP script.
PDFTK General Tutorial
Firstly, a blank PDF file should reside on your server. The empty fields should be labeled such that you can reference them.
When a user inputs information via your form, the data should be sanitized and inserted into an FDF (Forms Document File).
Once you have your FDF completed, in your PHP script, run:
exec('pdftk blank.pdf fill_form new.fdf output finished.pdf');
Where blank.pdf is the empty PDF, new.fdf is the FDF you just created, and finished.pdf is the name of the file you want pdftk to create for you.
Thanks for your replies .I found solution in TCPDF to show checkboxes. Just use different images, one for checked checkbox and other for unchecked
I want to open a webpage (whose URL is given as the commandline argument) and then want to save the content of that webpage as a .txt file.
Remember, I need the .txt file and not the source of the webpage.
I tried my hand with selenium and it works fine. But now I want something that doesn't open the real browser as opening the browser and loading a page in it is a time consuming task.
I want to do it in java.
By content, I mean the text (without markups) which we get when we save a webpage in IE by going to "Save As" and then selecting ".txt" as the output format of the file.
If I understand correctly your question, you want to render the page and copy the rendered text without using a navigator.
For this, you'll need a headless browser. HTMLUnit would be a good choice.
To get the text content, you could do it like this (not tested) :
WebClient c = new WebClient(BrowserVersion.INTERNET_EXPLORER_6);
TextPage tp = c.getPage("yoururl");
String content = tp.getContent();
(see Javadoc)
Hmm, I'd even code that from scratch, does not seem as a complex thing and might not be even worth adding a dependency on another library to your project:
Open a URLConnection to that URL
Get a stream from the connection, apply regex to strip out all the HTML to the data. If the page is not expected to be too large for you memory requirements :) read the page into a String then apply the regex. Alternatively, give a shoot to what's described here (I have no experience with the way described there though).
Save output to a txt.