How to use CdpInfo class of org.openqa.selenium.devtools package

Best Selenium code snippet using org.openqa.selenium.devtools.CdpInfo

copy

Full Screen

...4import com.codeborne.selenide.WebDriverRunner;5import org.junit.jupiter.api.*;6import org.openqa.selenium.Capabilities;7import org.openqa.selenium.chrome.ChromeDriver;8import org.openqa.selenium.devtools.CdpInfo;9import org.openqa.selenium.devtools.CdpVersionFinder;10import org.openqa.selenium.devtools.Connection;11import org.openqa.selenium.devtools.DevTools;12import org.openqa.selenium.devtools.noop.NoOpCdpInfo;13import org.openqa.selenium.devtools.v91.fetch.Fetch;14import org.openqa.selenium.devtools.v91.fetch.model.HeaderEntry;15import org.openqa.selenium.devtools.v91.network.Network;16import org.openqa.selenium.devtools.v91.network.model.AuthChallengeResponse;17import org.openqa.selenium.devtools.v91.network.model.Request;18import org.openqa.selenium.devtools.v91.network.model.RequestId;19import org.openqa.selenium.devtools.v91.network.model.RequestWillBeSent;20import org.openqa.selenium.devtools.v91.performance.Performance;21import org.openqa.selenium.devtools.v91.performance.model.Metric;22import org.openqa.selenium.remote.RemoteWebDriver;23import org.openqa.selenium.remote.http.ClientConfig;24import org.openqa.selenium.remote.http.HttpClient;25import java.net.MalformedURLException;26import java.net.URI;27import java.net.URISyntaxException;28import java.net.URL;29import java.util.ArrayList;30import java.util.Base64;31import java.util.List;32import java.util.Map;33import java.util.Optional;34import java.util.concurrent.ConcurrentHashMap;35import java.util.concurrent.TimeUnit;36import static java.util.Optional.empty;37import static org.awaitility.Awaitility.await;38import static org.junit.jupiter.api.Assertions.*;39import static com.codeborne.selenide.Condition.attribute;40import static com.codeborne.selenide.Selenide.*;41public class MainPageTest {42 @BeforeAll43 public static void setUpAll() {44 Configuration.browserSize = "1280x800";45 }46 @Test47 public void metricsTest() {48 DevTools devTools = getLocalDevTools();49 devTools.send(Performance.enable(empty()));50 open("https:/​/​www.jetbrains.com/​");51 List<Metric> send = devTools.send(Performance.getMetrics());52 assertTrue(send.size() > 0);53 send.forEach(it -> System.out.printf("%s: %s%n", it.getName(), it.getValue()));54 }55 @Test56 public void getResponseTest() {57 DevTools devTools = getLocalDevTools();58 devTools.send(Network.enable(empty(), empty(), empty()));59 final List<RequestWillBeSent> requests = new ArrayList<>();60 final List<String> responses = new ArrayList<>();61 devTools.addListener(Network.requestWillBeSent(), req -> {62 if (req.getRequest().getUrl().contains("proxy/​services/​credit-application/​async/​api/​external/​v1/​request/​parameters")) {63 requests.add(req);64 }65 });66 devTools.addListener(Network.responseReceived(),67 entry -> {68 if (requests.size() == 0) {69 return;70 }71 RequestWillBeSent request = requests.get(0);72 if (request != null && entry.getRequestId().toString().equals(request.getRequestId().toString())) {73 Network.GetResponseBodyResponse send = devTools.send(Network.getResponseBody(request.getRequestId()));74 responses.add(send.getBody());75 }76 });77 open("https:/​/​www.sberbank.ru/​ru/​person/​credits/​money/​consumer_unsecured/​zayavka");78 await().pollThread(Thread::new)79 .atMost(10, TimeUnit.SECONDS)80 .until(() -> responses.size() == 1);81 System.out.println(responses.get(0));82 }83 @Test84 public void interceptRequestTest() {85 DevTools devTools = getLocalDevTools();86 devTools.send(Fetch.enable(empty(), empty()));87 String content = "[{\"title\":\"Todo 1\",\"order\":null,\"completed\":false},{\"title\":\"Todo 2\",\"order\":null,\"completed\":true}]";88 devTools.addListener(Fetch.requestPaused(), request -> {89 String url = request.getRequest().getUrl();90 String query = getUrl(url);91 if (url.contains("/​todos/​") && query == null) {92 List<HeaderEntry> corsHeaders = new ArrayList<>();93 corsHeaders.add(new HeaderEntry("Access-Control-Allow-Origin", "*"));94 corsHeaders.add(new HeaderEntry("Access-Control-Allow-Methods", "GET, POST, OPTIONS, DELETE"));95 devTools.send(Fetch.fulfillRequest(96 request.getRequestId(),97 200,98 Optional.of(corsHeaders),99 Optional.empty(),100 Optional.of(Base64.getEncoder().encodeToString(content.getBytes())),101 Optional.of("OK"))102 );103 } else {104 devTools.send(Fetch.continueRequest(105 request.getRequestId(),106 Optional.of(url),107 Optional.of(request.getRequest().getMethod()),108 request.getRequest().getPostData(),109 request.getResponseHeaders()));110 }111 });112 open("https:/​/​todobackend.com/​client/​index.html?https:/​/​todo-backend-spring4-java8.herokuapp.com/​todos/​");113 $$("#todo-list li").shouldHave(CollectionCondition.size(2));114 $$("#todo-list label").shouldHave(CollectionCondition.texts("Todo 1", "Todo 2"));115 }116 private String getUrl(String url) {117 try {118 return new URL(url).getQuery();119 } catch (MalformedURLException e) {120 throw new RuntimeException(e.getMessage(), e);121 }122 }123 private DevTools getLocalDevTools() {124 open();125 ChromeDriver driver = (ChromeDriver) WebDriverRunner.getWebDriver();126 DevTools devTools = driver.getDevTools();127 devTools.createSession();128 return devTools;129 }130 @Test131 public void devtoolsWithSelenoid() throws URISyntaxException {132 Configuration.remote = "http:/​/​localhost:4444/​wd/​hub";133 open();134 RemoteWebDriver webDriver = (RemoteWebDriver) WebDriverRunner.getWebDriver();135 Capabilities capabilities = webDriver.getCapabilities();136 CdpInfo cdpInfo = new CdpVersionFinder()137 .match(capabilities.getBrowserVersion())138 .orElseGet(NoOpCdpInfo::new);139 HttpClient.Factory factory = HttpClient.Factory.createDefault();140 URI uri = new URI(String.format("ws:/​/​localhost:4444/​devtools/​%s", webDriver.getSessionId()));141 Connection connection = new Connection(142 factory.createClient(ClientConfig.defaultConfig().baseUri(uri)),143 uri.toString());144 DevTools devTools = new DevTools(cdpInfo::getDomains, connection);145 devTools.createSession();146 devTools.send(Performance.enable(empty()));147 open("https:/​/​www.jetbrains.com/​");148 List<Metric> send = devTools.send(Performance.getMetrics());149 assertTrue(send.size() > 0);150 send.forEach(it -> System.out.printf("%s: %s%n", it.getName(), it.getValue()));151 }152}...

Full Screen

Full Screen
copy

Full Screen

1package ch.qarts.tattool.webplatform.util;2import lombok.SneakyThrows;3import org.openqa.selenium.Capabilities;4import org.openqa.selenium.devtools.CdpVersionFinder;5import org.openqa.selenium.devtools.DevTools;6import org.openqa.selenium.devtools.SeleniumCdpConnection;7import org.openqa.selenium.remote.DesiredCapabilities;8import org.openqa.selenium.remote.RemoteWebDriver;9import java.net.URL;10import java.util.Map;11import java.util.function.Supplier;12public class DevtoolsUtils {13 @SneakyThrows14 public static DevTools getDevtools(RemoteWebDriver driver, URL url) {15 /​/​ TODO remove when there is a viable /​ documented option from selenium16 Supplier<Capabilities> fixCdp = () -> {17 Capabilities other = new DesiredCapabilities();18 var seCdp = (String) driver.getCapabilities().getCapability("se:cdp");19 var sessionPos = seCdp.indexOf("/​session");20 var seCdpFixed = String.format("ws:/​/​%s:%s%s", url.getHost(), url.getPort(), seCdp.substring(sessionPos));21 return driver.getCapabilities().merge(new DesiredCapabilities(Map.of("se:cdp", seCdpFixed)));22 };23 var cdpInfo = new CdpVersionFinder().match(driver.getCapabilities().getBrowserVersion()).orElseThrow(IllegalAccessException::new);24 return new DevTools(cdpInfo::getDomains, SeleniumCdpConnection.create(fixCdp.get()).orElseThrow(IllegalAccessException::new));25 }26 @SneakyThrows27 public static DevTools getDevtools(RemoteWebDriver driver) {28 var cdpInfo = new CdpVersionFinder().match(driver.getCapabilities().getBrowserVersion()).orElseThrow(IllegalStateException::new);29 return new DevTools(cdpInfo::getDomains, SeleniumCdpConnection.create(driver).orElseThrow(IllegalAccessException::new));30 }31}...

Full Screen

Full Screen
copy

Full Screen

...15/​/​ specific language governing permissions and limitations16/​/​ under the License.17package org.openqa.selenium.devtools.v86;18import com.google.auto.service.AutoService;19import org.openqa.selenium.devtools.CdpInfo;20@AutoService(CdpInfo.class)21public class V86CdpInfo extends CdpInfo {22 public V86CdpInfo() {23 super(86, V86Domains::new);24 }25}...

Full Screen

Full Screen
copy

Full Screen

...15/​/​ specific language governing permissions and limitations16/​/​ under the License.17package org.openqa.selenium.devtools.v85;18import com.google.auto.service.AutoService;19import org.openqa.selenium.devtools.CdpInfo;20@AutoService(CdpInfo.class)21public class V85CdpInfo extends CdpInfo {22 public V85CdpInfo() {23 super(85, V85Domains::new);24 }25}...

Full Screen

Full Screen
copy

Full Screen

...15/​/​ specific language governing permissions and limitations16/​/​ under the License.17package org.openqa.selenium.devtools.v84;18import com.google.auto.service.AutoService;19import org.openqa.selenium.devtools.CdpInfo;20@AutoService(CdpInfo.class)21public class V84CdpInfo extends CdpInfo {22 public V84CdpInfo() {23 super(84, V84Domains::new);24 }25}...

Full Screen

Full Screen
copy

Full Screen

...15/​/​ specific language governing permissions and limitations16/​/​ under the License.17package org.openqa.selenium.devtools.v89;18import com.google.auto.service.AutoService;19import org.openqa.selenium.devtools.CdpInfo;20@AutoService(CdpInfo.class)21public class V89CdpInfo extends CdpInfo {22 public V89CdpInfo() {23 super(89, V89Domains::new);24 }25}...

Full Screen

Full Screen
copy

Full Screen

...15/​/​ specific language governing permissions and limitations16/​/​ under the License.17package org.openqa.selenium.devtools.v91;18import com.google.auto.service.AutoService;19import org.openqa.selenium.devtools.CdpInfo;20@AutoService(CdpInfo.class)21public class V91CdpInfo extends CdpInfo {22 public V91CdpInfo() {23 super(91, V91Domains::new);24 }25}...

Full Screen

Full Screen
copy

Full Screen

...15/​/​ specific language governing permissions and limitations16/​/​ under the License.17package org.openqa.selenium.devtools.v88;18import com.google.auto.service.AutoService;19import org.openqa.selenium.devtools.CdpInfo;20@AutoService(CdpInfo.class)21public class V88CdpInfo extends CdpInfo {22 public V88CdpInfo() {23 super(88, V88Domains::new);24 }25}...

Full Screen

Full Screen

CdpInfo

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.devtools.DevTools;2import org.openqa.selenium.devtools.v91.network.Network;3import org.openqa.selenium.devtools.v91.network.model.CdpInfo;4import org.openqa.selenium.devtools.v91.network.model.ConnectionType;5import org.openqa.selenium.devtools.v91.network.model.Initiator;6import org.openqa.selenium.devtools.v91.network.model.Request;7import org.openqa.selenium.devtools.v91.network.model.ResourceType;8import org.openqa.selenium.devtools.v91.network.model.Response;9import org.openqa.selenium.devtools.v91.network.model.SignedExchangeInfo;10import org.openqa.selenium.devtools.v91.network.model.Timestamp;11import org.openqa.selenium.devtools.v91.network.model.WallTime;12public class NetworkEvents {13 public static void main(String[] args) {14 WebDriver driver = new ChromeDriver();15 DevTools devTools = ((ChromeDriver) driver).getDevTools();16 devTools.createSession();17 devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));18 devTools.addListener(Network.requestWillBeSent(), request -> {19 System.out.println(request.getRequestId());20 System.out.println(request.getLoaderId());21 System.out.println(request.getDocumentURL());22 System.out.println(request.getRequest().getUrl());23 System.out.println(request.getRequest().getMethod());24 System.out.println(request.getRequest().getHeaders());25 System.out.println(request.getRequest().getInitialPriority());26 System.out.println(request.getRequest().getReferrerPolicy());27 System.out.println(request.getTimestamp());28 System.out.println(request.getWallTime());29 System.out.println(request.getInitiator().getType());30 System.out.println(request.getInitiator().getStack().getCallFrames());31 System.out.println(request.getRedirectResponse());32 System.out.println(request.getType());33 System.out.println(request.getFrameId());34 System.out.println(request.hasUserGesture());35 });36 devTools.addListener(Network.requestServedFromCache(), requestServedFromCache -> {37 System.out.println(requestServedFromCache.getRequestId());38 });39 devTools.addListener(Network.responseReceived(), responseReceived -> {40 System.out.println(responseReceived.getRequestId());41 System.out.println(responseReceived.getLoaderId());42 System.out.println(responseReceived.getTimestamp());43 System.out.println(responseReceived.getType());44 System.out.println(responseReceived.getResponse().getUrl());45 System.out.println(responseReceived.getResponse().getStatus());46 System.out.println(responseReceived.getResponse().getStatusText());47 System.out.println(responseReceived.getResponse().getHeaders());48 System.out.println(responseReceived.getResponse().get

Full Screen

Full Screen

CdpInfo

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.devtools.DevTools;2import org.openqa.selenium.devtools.v92.cdp.CdpInfo;3import org.openqa.selenium.devtools.v92.cdp.CdpInfo.Version;4import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo;5import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoBuilder;6import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoBuilder.VersionInfoBuilderImpl;7import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl;8import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplBuilder;9import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplBuilderImpl;10import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplImpl;11import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplImpl.VersionInfoImplImplBuilder;12import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplImpl.VersionInfoImplImplBuilderImpl;13import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplImpl.VersionInfoImplImplImpl;14import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplImpl.VersionInfoImplImplImpl.VersionInfoImplImplImplBuilder;15import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplImpl.VersionInfoImplImplImpl.VersionInfoImplImplImplBuilderImpl;16import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplImpl.VersionInfoImplImplImpl.VersionInfoImplImplImplImpl;17import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplImpl.VersionInfoImplImplImpl.VersionInfoImplImplImplImpl.VersionInfoImplImplImplImplBuilder;18import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplImpl.VersionInfoImplImplImpl.VersionInfoImplImplImplImpl.VersionInfoImplImplImplImplBuilderImpl;19import org.openqa.selenium.devtools.v92.cdp.CdpInfo.VersionInfo.VersionInfoImpl.VersionInfoImplImpl.VersionInfoImplImplImpl.VersionInfoImplImplImplImpl.VersionInfoImplImplImplImplImpl;20import

Full Screen

Full Screen

CdpInfo

Using AI Code Generation

copy

Full Screen

1ChromeDriver driver = new ChromeDriver(); 2ChromeDevTools devTools = driver.getDevTools();3CdpInfo cdpInfo = new CdpInfo();4cdpInfo.setDomain("Network");5cdpInfo.setCommand("requestWillBeSent");6cdpInfo.setParams("requestId", "requestId");7cdpInfo.setEvent("responseReceived");8cdpInfo.setParams("requestId", "requestId");9devTools.addCdpInfo(cdpInfo);10devTools.send(Network.enable());11devTools.send(Network.disable());12driver.quit();

Full Screen

Full Screen

CdpInfo

Using AI Code Generation

copy

Full Screen

1System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");2ChromeOptions options = new ChromeOptions();3options.setExperimentalOption("debuggerAddress", "localhost:9222");4WebDriver driver = new ChromeDriver(options);5CdpInfo cdpInfo = ((ChromeDriver)driver).getDevTools().getInfo();6System.out.println(cdpInfo.getBrowserVersion());

Full Screen

Full Screen

CdpInfo

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.devtools.DevTools;2import org.openqa.selenium.devtools.v91.browser.Browser;3import org.openqa.selenium.devtools.v91.browser.model.CdpInfo;4import org.openqa.selenium.devtools.v91.browser.model.GetBrowserCommandLine;5import org.openqa.selenium.devtools.v91.browser.model.GetVersionResponse;6import org.openqa.selenium.devtools.v91.browser.model.GetWindowBoundsResponse;7import org.openqa.selenium.devtools.v91.browser.model.SetWindowBounds;8import org.openqa.selenium.devtools.v91.browser.model.WindowState;9import org.openqa.selenium.devtools.v91.emulation.Emulation;10import org.openqa.selenium.devtools.v91.emulation.model.ScreenOrientation;11import org.openqa.selenium.devtools.v91.emulation.model.VirtualTimePolicy;12import org.openqa.selenium.devtools.v91.fetch.Fetch;13import org.openqa.selenium.devtools.v91.fetch.model.AuthChallengeResponseResponse;14import org.openqa.selenium.devtools.v91.fetch.model.RequestPaused;15import org.openqa.selenium.devtools.v91.fetch.model.RequestPattern;16import org.openqa.selenium.devtools.v91.network.Network;17import org.openqa.selenium.devtools.v91.network.model.Headers;18import org.openqa.selenium.devtools.v91.network.model.Request;19import org.openqa.selenium.devtools.v91.network.model.Response;20import org.openqa.selenium.devtools.v91.page.Page;21import org.openqa.selenium.devtools.v91.page.model.Viewport;22import org.openqa.selenium.devtools.v91.runtime.Runtime;23import org.openqa.selenium.devtools.v91.runtime.model.ConsoleAPICalled;24import org.openqa.selenium.devtools.v91.runtime.model.RemoteObject;25import org.openqa.selenium.devtools.v91.storage.Storage;26import org.openqa.selenium.devtools.v91.storage.model.CacheStorageContentUpdated;27import org.openqa.selenium.devtools.v91.storage.model.CacheStorageDataEntry;28import org.openqa.selenium.devtools.v91.storage.model.CacheStorageListUpdated;29import org.openqa.selenium.devtools.v91.storage.model.CacheStorageResponse;30import org.openqa.selenium.devtools.v91.storage.model.CacheStorageUpdated;31import org.openqa.selenium.devtools.v91.storage.model.Cookie;32import org.openqa.selenium.devtools.v91.storage.model.CookieParam;33import org.openqa.selenium.devtools.v91.storage.model.Storage

Full Screen

Full Screen
copy
1String value=""1000000.00""2DecimalFormat myFormatter = new DecimalFormat("###,###.##");3String output = myFormatter.format(value);4WebElement webElement= driver.findElement(By.ById("req8input"));5webElement.sendKeys("100);6assertEquals(output, webElement.getAttribute("value"));7
Full Screen
copy
1WebElement el = driver.findElement(By.id("req8input"));2
Full Screen

StackOverFlow community discussions

Questions
Discussion

How to click on the print button on a web page using Selenium

Running Selenium scripts with JMeter

Selenium ChromeDriver gives &quot;InitializeSandbox() called with multiple threads in process gpu-process&quot; error

Selenium WebDriver Firefox error - Failed to connect

Possible issue with Chromedriver 78, Selenium can not find web element of PDF opened in Chrome

Selenium chromedriver disable logging or redirect it java

How to automate a chat application using Selenium/Webdriver?

Selenium and xpath: finding a div with a class/id and verifying text inside

returned error:java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission while using touchaction class in appium

Selenium Webdriver - Issue with FirefoxDriver: Error: cannot open display: :0.0

Here's my insight.

First of all, you need to wait for the page to load in order to interact with the Print button. The best way to go is to use built-in mechanism: selenium waits - wait for the Print button to be clickable:

// open print dropdown
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.print-button"))).click();

// click print button
WebElement printButton = driver.findElement(By.cssSelector("button.print-popup-button"));
printButton.click();

Okay, if you run it using ChromeDriver:

package com.company;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;


public class Main {
    public static void main(String[] args) {
        String url = "https://www.google.com/maps/dir/40.4515849,-3.6903752/41.380896,2.1228198/@40.4515849,-3.6903752/am=t/?hl=en";

        WebDriver driver = new ChromeDriver();
        driver.get(url);

        // open print dropdown
        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.print-button"))).click();

        // click print button
        WebElement printButton = driver.findElement(By.cssSelector("button.print-popup-button"));
        printButton.click();

        // now what? 
    }
}

You'll see the Chrome Print Preview dialog, which is, unfortunately, out of scope for selenium:

enter image description here

But, there is a hope, if you examine available Chrome arguments, you would see that there is the relevant one:

--disable-print-preview - Disables print preview (For testing, and for users who don't like us. :[ )

Okay, let's try it out:

ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-print-preview");

WebDriver driver = new ChromeDriver(options);
driver.get(url);

Now, there is a system print dialog being shown:

enter image description here

Selenium cannot control it too. So, nope, there is no hope. Oh, wait!


Okay, if we are out of scope of selenium, let's use tools that can help us to click that Print button in the dialog - Robot class:

This class is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed.

We'll initialize the Robot and will send Enter key when the print dialog would show up:

package com.company;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.awt.*;
import java.awt.event.KeyEvent;


public class Main {
    public static void main(String[] args) throws AWTException, InterruptedException {
        String url = "https://www.google.com/maps/dir/40.4515849,-3.6903752/41.380896,2.1228198/@40.4515849,-3.6903752/am=t/?hl=en";

        Robot r = new Robot();
        r.delay(1000);

        WebDriver driver = new ChromeDriver();
        driver.get(url);

        // open print dropdown
        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.print-button"))).click();

        // click print button
        WebElement printButton = driver.findElement(By.cssSelector("button.print-popup-button"));
        printButton.click();

        Thread.sleep(2000);

        r.keyPress(KeyEvent.VK_ENTER);
        r.keyRelease(KeyEvent.VK_ENTER);
    }
}

Other options are to use:

  • sikuli - you would need an image of the print button in order for sikuli to locate it and click
  • autoit

Also see:

https://stackoverflow.com/questions/26522739/how-to-click-on-the-print-button-on-a-web-page-using-selenium

Blogs

Check out the latest blogs from LambdaTest on this topic:

Best Usability Testing Tools For Your Website

When a user comes to your website, you have time in seconds to influence them. Web usability is the key to gain quick trust, brand recognition and ensure user retention.

What To Expect From The Latest Version Of Selenium 4 Alpha?

All of us belonging to the testing domain are familiar with Selenium, one of the most popular open source automation tools available in the industry. We were pretty excited in August 2018 when Simon Stewart, Selenium’s founding member officially announced the release date of Selenium 4 and what new features this latest selenium version will bring to the users.

Are You Confused Between Scripting Testing and Record &#038; Replay Testing?

So you are planning to make a move towards automation testing. But you are continuously debated about which one to opt for? Should you make a move towards Record and Replay automation testing? Or Would you rather stick to good old scripting? In this article, we will help you gain clarity among the differences between these two approaches i.e. Record & Replay & Scripting testing.

Why Understanding Regression Defects Is Important For Your Next Release

‘Regression’ a word that is thought of with a lot of pain by software testers around the globe. We are aware of how mentally taxing yet indispensable Regression testing can be for a release window. Sometimes, we even wonder whether regression testing is really needed? Why do we need to perform it when a bug-free software can never be ready? Well, the answer is Yes! We need to perform regression testing on regular basis. The reason we do so is to discover regression defects. Wondering what regression defects are and how you can deal with them effectively? Well, in this article, I will be addressing key points for you to be aware of what regression defects are! How you can discover and handle regression defects for a successful release.

Top 13 Skills of A Good QA Manager in 2021

I believe that to work as a QA Manager is often considered underrated in terms of work pressure. To utilize numerous employees who have varied expertise from one subject to another, in an optimal way. It becomes a challenge to bring them all up to the pace with the Agile development model, along with a healthy, competitive environment, without affecting the project deadlines. Skills for QA manager is one umbrella which should have a mix of technical & non-technical traits. Finding a combination of both is difficult for organizations to find in one individual, and as an individual to accumulate the combination of both, technical + non-technical traits are a challenge in itself.

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in CdpInfo

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful