You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using selenium to drive chrome, rendering HTML pages into PDF, and I have succeeded. However, I found that I cannot set the styles for headers and footers, nor can I control their visibility. But when operating with chrome in the browser, these functions are indeed available. Since I can use the method webDriver.print(new PrintOptions()).getContent(); in selenium to set parameters such as orientation, scale, background, shrinkToFit, pageSize, pageMargin, and pageRanges through PrintOptions(), why can't other properties be set together? After checking the source code and information, I found that it is not supported and raised an issue on the selenium project. The response was that this requires webdriver support.
It seems that everything is supported except for setting the header and footer.
The following are the issues I raised in Selenium: SeleniumHQ/selenium#12763 (comment)
The following is the information I have looked up: https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/print/PrintOptions.html
I have reviewed the source code and documentation, but it seems that I cannot find a way to set --print-header-template in PrintOptions. According to my search on Python methods, it appears that this can only be set in ChromeOptions. Is there a better way for me to set this property in PrintOptions or RemoteWebDriver?
Also, I have another question. Currently, I am using springboot integrated with selenium. Here is my code:
@Data
public class CpPrintOptions extends PrintOptions {
public Map<String, Object> toMap() {
final Map<String, Object> options = new HashMap<>(7);
options.put("page", getPageSize());
options.put("orientation", getOrientation().toString());
options.put("scale", getScale());
options.put("shrinkToFit", getShrinkToFit());
options.put("background", getBackground());
final String[] effectivePageRanges = getPageRanges();
if (effectivePageRanges != null) {
options.put("pageRanges", effectivePageRanges);
}
options.put("margin", getPageMargin());
options.put("displayHeaderFooter", true);
options.put("headerTemplate", "<span style=\"font-size:8px; margin-left: 5px\">Page <span class=pageNumber></span> of <span class=totalPages></span></span>");
options.put("footerTemplate", "<span style=\"font-size:8px; margin-left: 5px\">Generated on {datetime.now().strftime(\"%m/%d/%Y at %H:%M\")} - url = <span class=url></span></span>");
return options;
}
}
I tried to integrate PrintOptions() and specify the properties, but it seems not to work.
The text was updated successfully, but these errors were encountered:
I am using selenium to drive
chrome
, rendering HTML pages into PDF, and I have succeeded. However, I found that I cannot set the styles for headers and footers, nor can I control their visibility. But when operating with chrome in the browser, these functions are indeed available. Since I can use the methodwebDriver.print(new PrintOptions()).getContent();
inselenium
to set parameters such as orientation, scale, background, shrinkToFit, pageSize, pageMargin, and pageRanges throughPrintOptions()
, why can't other properties be set together? After checking the source code and information, I found that it is not supported and raised an issue on the selenium project. The response was that this requires webdriver support.It seems that everything is supported except for setting the header and footer.
The following are the issues I raised in
Selenium
:SeleniumHQ/selenium#12763 (comment)
The following is the information I have looked up:
https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/print/PrintOptions.html
I have reviewed the source code and documentation, but it seems that I cannot find a way to set --print-header-template in PrintOptions. According to my search on Python methods, it appears that this can only be set in ChromeOptions. Is there a better way for me to set this property in PrintOptions or RemoteWebDriver?
Also, I have another question. Currently, I am using springboot integrated with selenium. Here is my code:
I tried to integrate
PrintOptions()
and specify the properties, but it seems not to work.The text was updated successfully, but these errors were encountered: