-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathFile_upload.java
More file actions
64 lines (48 loc) · 2.2 KB
/
File_upload.java
File metadata and controls
64 lines (48 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//Sample Selenium Webdriver code in Java
import java.util.*;
import java.net.*;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.Keys;
import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.LocalFileDetector;
import java.util.concurrent.TimeUnit;
import java.net.URL;
public class File_upload {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","./chromedriver");
DesiredCapabilities capabillities = DesiredCapabilities.chrome();
String USERNAME = "USERNAME";
String ACCESS_KEY = "ACCESS_KEY";
String url = "https://" + USERNAME + ":" + ACCESS_KEY + "@ondemand.saucelabs.com:443/wd/hub";
URL start_url;
try {
start_url = new URL(url);
} catch(MalformedURLException ex) {
return;
}
//-----------------------------------
// These are the Remotewebdriver lines
// Comment them out to run locally
RemoteWebDriver driver = new RemoteWebDriver(start_url, capabillities);
driver.setFileDetector(new LocalFileDetector());
//------------------------------------
//------------------------------------
// These are the local webdriver lines
// Uncomment them to run locally
//WebDriver driver = new ChromeDriver();
//driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
//------------------------------------
driver.get("http://xndev.com/display-image/");
WebElement upload = driver.findElement(By.xpath("//*[@id='post-2122']/div/input"));
//In windows the slash below will need to be reversed
upload.sendKeys(System.getProperty("user.dir") + '/' + "broken_bulb.jpg");
WebElement img = driver.findElement(By.xpath("//img['data:image/jpeg;base64'=substring(@src,1,22)]"));
driver.quit();
}
}