How to use Selenium WebDriver on local webpage (on my PC) instead of one located somewhere online?
Try using this method:
webdriver.get("file:///D:/folder/abcd.html");
(or)
selenium = new WebDriverBackedSelenium(driver, "file:///D:/folder/abcd.html");
Selenium Web Driver With HTML Input Source
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.
Python Selenium Chrome Webdriver
You need to specify the path where your chromedriver is located.
Download chromedriver for your desired platform from here.
Place chromedriver on your system path, or where your code is.
If not using a system path, link your
chromedriver.exe
(For non-Windows users, it's just calledchromedriver
):browser = webdriver.Chrome(executable_path=r"C:\path\to\chromedriver.exe")
(Set
executable_path
to the location where your chromedriver is located.)If you've placed chromedriver on your System Path, you can shortcut by just doing the following:
browser = webdriver.Chrome()
If you're running on a Unix-based operating system, you may need to update the permissions of chromedriver after downloading it in order to make it executable:
chmod +x chromedriver
That's all. If you're still experiencing issues, more info can be found on this other StackOverflow article: Can't use chrome driver for Selenium
It's possible to do an XHR call and render the output with Selenium?
One option would be to make the XHR request using, for instance, requests
, save the response to a file and get()
it with selenium webdriver instance (How to use selenium webdriver on local (on my pc) webpage instead of locate somwhere on www?).
How to handle windows file upload using Selenium WebDriver?
// assuming driver is a healthy WebDriver instance
WebElement fileInput = driver.findElement(By.name("uploadfile"));
fileInput.sendKeys("C:/path/to/file.jpg");
Hey, that's mine from somewhere :).
In case of the Zamzar web, it should work perfectly. You don't click the element. You just type the path into it. To be concrete, this should be absolutely ok:
driver.findElement(By.id("inputFile")).sendKeys("C:/path/to/file.jpg");
In the case of the Uploadify web, you're in a pickle, since the upload thing is no input
, but a Flash object. There's no API for WebDriver that would allow you to work with browser dialogs (or Flash objects).
So after you click the Flash element, there'll be a window popping up that you'll have no control over. In the browsers and operating systems I know, you can pretty much assume that after the window has been opened, the cursor is in the File name
input. Please, make sure this assumption is true in your case, too.
If not, you could try to jump to it by pressing Alt + N, at least on Windows...
If yes, you can "blindly" type the path into it using the Robot
class. In your case, that would be something in the way of:
driver.findElement(By.id("SWFUpload_0")).click();
Robot r = new Robot();
r.keyPress(KeyEvent.VK_C); // C
r.keyRelease(KeyEvent.VK_C);
r.keyPress(KeyEvent.VK_COLON); // : (colon)
r.keyRelease(KeyEvent.VK_COLON);
r.keyPress(KeyEvent.VK_SLASH); // / (slash)
r.keyRelease(KeyEvent.VK_SLASH);
// etc. for the whole file path
r.keyPress(KeyEvent.VK_ENTER); // confirm by pressing Enter in the end
r.keyRelease(KeyEvent.VK_ENTER);
It sucks, but it should work. Note that you might need these: How can I make Robot type a `:`? and Convert String to KeyEvents (plus there is the new and shiny KeyEvent#getExtendedKeyCodeForChar()
which does similar work, but is available only from JDK7).
For Flash, the only alternative I know (from this discussion) is to use the dark technique:
First, you modify the source code of you the flash application, exposing
internal methods using the ActionScript's ExternalInterface API.
Once exposed, these methods will be callable by JavaScript in the browser.Second, now that JavaScript can call internal methods in your flash app,
you use WebDriver to make a JavaScript call in the web page, which will
then call into your flash app.This technique is explained further in the docs of the flash-selenium project.
(http://code.google.com/p/flash-selenium/), but the idea behind the technique
applies just as well to WebDriver.
Related Topics
How to Read Text from Hidden Element with Selenium Webdriver
Not Implementing All of the Methods of Interface. Is It Possible
Java Switch Statement Multiple Cases
Guessing the Encoding of Text Represented as Byte[] in Java
Matrix Multiplication in Apache Spark
How to Copy Hashmap (Not Shallow Copy) in Java
Java Conventions: Use Getters/Setters Within the Class
How to Convert Hex to Rgb Using Java
Detect Internet Connection Using Java
Block()/Blockfirst()/Blocklast() Are Blocking Error When Calling Bodytomono After Exchange()
How to Hide a Jframe in System Tray of Taskbar
How to Capture Video Using Jmf, But Without Installing Jmf
Access Maven Properties Defined in the Pom
Itext - Add Content to Existing PDF File
What Is Java_Home? How Does the Jvm Find the Javac Path Stored in Java_Home
Annotation to Make a Private Method Public Only for Test Classes