SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.63k stars 8.18k forks source link

[🐛 Bug]: Selenium sometimes returns a blank page #12544

Closed h928725721 closed 1 year ago

h928725721 commented 1 year ago

What happened?

I try to open an URL through Selenium, after Google Chrome opened and it showed a blank page.

But when I copied this URL to a new TAB and opened it, it could be displayed normally.

How can we reproduce the issue?

This scene is sporadic,most of the time it doesn't happened.

Relevant log output

here is my code:

server_path = '../browsermob-proxy-2.1.4/bin/browsermob-proxy.bat'
server_opetion = {'prot':8080,'use-littleproxy':False}
server = Server(path=server_path,options=server_options)
server.start()
proxy = server.create_proxy()
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--proxy-server={0}.format(proxy.proxy))
options.add_experimental_option('excludeSwitches',['enable-automation'])
options.add_experimental_option('excludeSwitches',['enable-logging'])

try:
    driver = webdriver.Chrome(executable_path='/chrome_driver/chromedriver.exe',options=options)
except Exception as e:
    latest_driver = ChromeDriverManager().install()
    driver = webdriver.Chrome(latest_driver,options = options)

driver.maximize_window()
wait = WebDriverWait(driver,10)
proxy.new_bar('google',options={'captureHeaders':True,'captureContent':True})
driver.get('url')

Operating System

windows 10

Selenium version

4.9.0

What are the browser(s) and version(s) where you see this issue?

115.0.5790.171

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriverManager().install()

Are you using Selenium Grid?

no

github-actions[bot] commented 1 year ago

@h928725721, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

diemol commented 1 year ago

Does it happen when you use Selenium without browser mob proxy?

SinghSuraj-04092002 commented 1 year ago

It seems like you're facing an issue where sometimes a URL opened through Selenium using ChromeDriver shows a blank page, even though the same URL opens normally when manually opened in a new tab. This sporadic behavior can be challenging to debug. Here are a few steps you can consider to troubleshoot the problem:

  1. Check Network Activity: Use the BrowserMob Proxy to capture network activity for both scenarios (Selenium and manual). Compare the network requests and responses to see if there's any difference.
  2. Logging and Debugging: Introduce logging statements at various points in your script to better understand the flow of execution. This could help identify any inconsistencies.
  3. Update Chrome and Drivers: Ensure you're using the latest version of Chrome, ChromeDriver, and Selenium. Sometimes compatibility issues can lead to unexpected behavior.
  4. Try Different WebDriver Methods: Instead of using get() method, you could try navigate.to() to see if there's any difference in behavior.
  5. Check JavaScript Errors: Use the WebDriver to execute JavaScript code on the page to check for any JavaScript errors that might be causing the issue.
  6. Headless Mode: Try running the browser in headless mode to see if the issue is specific to the browser window.
h928725721 commented 1 year ago

@diemol I haven't tried it because the problem occurs only in rare cases

titusfortner commented 1 year ago

This sounds like a network/proxy issue, unrelated to this code base. Regardless, if we can't reproduce it, we can't investigate it as a potential bug.

h928725721 commented 1 year ago

@titusfortner Alright ,thank you very much

github-actions[bot] commented 10 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.