-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Description
OS: Ubuntu 17.10
Selenium Version: 3.8.1
Browser: Chrome
Browser Version: 63.0.3239.132
Expected Behavior -
For JavaScript libraries such as a JavaScript PDF viewer to exhibit the same behavior if served from a localhost web server vs. remote web sites using a FQDN.
Actual Behavior -
Using a JavaScript library, PDFs on remote websites can be viewed with snapshots taken using the Xvfb virtual framebuffer. However, when running that exact same JavaScript library on localhost:8888 to view and then snapshot locally stored PDFs, no PDF content is rendered using either Xvfb or Headless Chrome.
Steps to reproduce -
This works as expected:
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
chromeOptions = webdriver.ChromeOptions()
#chromeOptions.add_argument("headless")
driver = webdriver.Chrome(chrome_options=chromeOptions)
driver.get("https://mozilla.github.io/pdf.js/web/viewer.html")
timeout = 5
try:
element_present = EC.presence_of_element_located((By.CLASS_NAME, 'dropdownToolbarButton'))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print "Timed out waiting for page to load"
time.sleep(5)
driver.get_screenshot_as_file('screenshot.png')
driver.quit()
This does not, even though the only difference is a web server running on localhost:
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
chromeOptions = webdriver.ChromeOptions()
#chromeOptions.add_argument("headless")
driver = webdriver.Chrome(chrome_options=chromeOptions)
driver.get("http://localhost:8888/web/viewer.html?file=%2Ftest%2Fpdfs%2F1.pdf#search=JavaScript")
timeout = 5
try:
element_present = EC.presence_of_element_located((By.CLASS_NAME, 'dropdownToolbarButton'))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print "Timed out waiting for page to load"
time.sleep(5)
driver.get_screenshot_as_file('screenshot.png')
driver.quit()
There is a five second delay loop right above the screenshot to make sure there is enough time for the PDF to be rendered in both contexts, but nothing is rendered via localhost for some reason.
Are there any debugging options I can enable to trace through what's happening?