Selenium Web Driver With HTML Input Source - selenium-webdriver

If you are using Selenium in Java and have a string of HTML and JavaScript Source are you able to have a real browser render the source with the webdriver?

Yes you can open the HTML file in a browser. You have to specify the "file:///" protocol in get() method to open the file in browser. You can refer below code.
webdriver.get("file:///<filePath>/fileName.html");
Do let us know if that helps you out.

Related

Grab and save SVG File using selenium - C# Selenium chromedriver WinForm

I am writing WhatsApp tool in C# winform using Selenium ChromeDriver.
I have handled all operations like sending the message, clicking the attachment and all from WhatsApp web using Selenium ChromeDriver.
I want to read the WhatsApp web's QR Code which is in SVG format. I want to read the SVG File and convert and save as image in local.
I could save the QR Code using snapshot, but I don't prefer using this because I have to maintain vertical scroll position to bring full QR Code on screen.
So please help me save svg file image using chromedriver
Thank you.
-Ishrar
I'm not sure of the specific commands in Selenium, but can't you just:
copy the SVG code via Javascript/a Selenium method
then create a new .svg file in Java and save this copied svg code as the contents?

How can I scrape this page with selenium and chromedriver in python language?

I'm trying to scrape data from the website “http://www.nmpa.gov.cn/” by using selenium and chromedriver. When I was running the code, chromedriver succeeded in inputing the url but couldn't load the page, displaying a blank page. I tried to switch the target website into google.com and succeeded in scraping. I concluded that the target website server detected selenium and refused sending back data. So how can I scrape the data from website with selenium and chromedriver in python language. I'm quite a Python beginner, thank you for your kind help in advance. Here is my simple code:
from selenium import webdriver
my_driver_path = r"C:\python chrome driver\chromedriver.exe"
driver = webdriver.Chrome(executable_path=my_driver_path)
driver.get('http://www.nmpa.gov.cn/')
here is the photo of the issue:
enter image description here
The issue here is more on HTML than on Python.
If you check the source code of the page (you can do this by adding print(driver.page_source), you will see that it contains a meta tag with the http-equiv attribute set to "refresh":
<HTML><HEAD><title>NMPA</title></HEAD>
<body>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="refresh" content="0;URL=/WS04/CL2042/">
</HTML>
What this tag does is direct the browser to go to the given URL (/WS04/CL2042/, in a badly formatted attribute that the browser is luckily able to understand). So, instead of scraping http://www.nmpa.gov.cn/, you have to scrape http://www.nmpa.gov.cn/WS04/CL2042/.
If you change your code to access this other link, you will see that then you can get the whole page. You can either hard-code the new link or safely concatenate the first link with the "refresh" destination with a method like urllib.parse.join(): https://docs.python.org/3.7/library/urllib.parse.html#urllib.parse.urljoin.

Can we verify image dimension in a PDF by Selenium webdriver?

I have a requirement to verify the image dimension of a PDF, which is getting downloaded and saved to a particular location. I am curious to know that, is there any way we can check the image dimension of a PDF using Selenium WebDriver? Please help.
Selenium WebDriver is for browser automation. If your requirement is to validate pdf files, contents, images in the pdfs etc, I would suggest you to use the below pdf library.
http://www.testautomationguru.com/introducing-pdfutil-to-compare-pdf-files-extract-resources/

How do I make selenium see the network requests made by a web browser?

I have a dotnet Selenium web driver app.
When I'm testing the page one of the things I need to confirm is that a flash object on the page has pulled correct content from a content store on my site. (i.e. the flash object should be loading content from /stuff/info.txt and including that content within the animation.)
As a human looking at this I can use the chrome network tab and see that /stuff/info.txt has been accessed.
How can I make Selenium execute a similar watch and see the network requests made by a web browser?
I did not wrote this, neither tested it however someone did it here: http://www.softwareishard.com/blog/firebug/automate-page-load-performance-testing-with-firebug-and-selenium/
Basically all the requests are exported via netexport and firebug plugins inside a HAR (Http ARchive file)
Please give us your feedback if you give it a try!
Cheers !
I assume you want to automate the process which the developer tools of browsers does. Something like firebug but for verification using Code.
I don't believe Selenium has such features. For now, you will not be able to achieve this.

Selenium Webdriver: download files on firefox using DesiredCapabilities class

Is there an alternative to firefox profile to download files, i.e. through desiredcapability on selenium webdriver?
I want to download files from a website but through desiredcapabilities.
So one piece of code is applicable accross all the browsers.
In theory, you could create a AugmenterProvider and pass it to the Augmenter class but I have not done so and its beyond my skill.

Resources