Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sgrillon14/4b2a684e1548ec778eaa2e2089d2cca4 to your computer and use it in GitHub Desktop.
Save sgrillon14/4b2a684e1548ec778eaa2e2089d2cca4 to your computer and use it in GitHub Desktop.
import java.awt.AWTException;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import com.github.noraui.utils.Utilities.OperatingSystem;
import com.github.noraui.utils.Utilities.SystemArchitecture;
public class Bot {
public static void main(String[] args) throws IOException, AWTException, InterruptedException {
final OperatingSystem currentOperatingSystem = OperatingSystem.getCurrentOperatingSystem();
String pathWebdriver = String.format("src/test/resources/drivers/%s/googlechrome/%s/chromedriver%s", currentOperatingSystem.getOperatingSystemDir(),
SystemArchitecture.getCurrentSystemArchitecture().getSystemArchitectureName(), currentOperatingSystem.getSuffixBinary());
System.setProperty("webdriver.chrome.driver", pathWebdriver);
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
// options.addArguments("--headless");
WebDriver driver = new ChromeDriver(options);
driver.get("http://rd.huangpuqu.sh.cn/website/index.htm");
Thread.sleep(5000);
final byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
FileUtils.forceMkdir(new File(System.getProperty("user.dir") + File.separator + "downloadFiles"));
FileUtils.writeByteArrayToFile(new File(System.getProperty("user.dir") + File.separator + "downloadFiles" + File.separator + "bot.jpg"), screenshot);
driver.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment