首页 > 解决方案 > Can selenium be used to click on print and then save as pdf?

问题描述

I am trying to download as pdfs a number of urls that are password protected. I access them with selenium, but all my html to pdf efforts end up either ruining the format in the final pdf or not preserving the character set. Is it possible to use selenium to right click-print-save as pdf in safari?

标签: pythonseleniumpdfsafari

解决方案


Right click action in Selenium web driver can be done using Actions class. Right Click operation is also called Context Click in Selenium. Pre-defined method context click provided by Actions class is used to perform right click operation. Below is the code to demonstrate right click operation using Actions class.

Actions actions = new Actions(driver);
WebElement elementLocator = driver.findElement(By.id("ID"));
actions.contextClick(elementLocator).perform();

Actions class is used for any special input you might need, to simulate real user using a keyboard or the mouse to perform an action on the page.


推荐阅读