Python Forum
Issue calling Chromedriver.exe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue calling Chromedriver.exe
#1
Back to my project this morning and my goal was to hide or auto close the window that Chromedriver pops up and doesn't bother to close. I had formatted my image so it had a border around it to allow me the ability to measure the size of the output. Since I was past that part I turned off the boarder and ran my code which has not changed since yesterday when it worked just fine.

The only thing different in this process was that I change change the html in my label-formatter from
Quote:<table height="240" Width="390" border="1">

to...
Quote:<table height="240" Width="390" border="0">

when I ran my code that calls the Chromedriver, instead of seeing the annoying popup window that tells me that Chomedriver has been called, I get this!

[Image: chromedriver-error.png]

So I changed my html page back to border="1" and got the very same result.

I have no idea what has changed from yesterday when this code worked perfectly (except for the annoying popup window) but something is causing my code to fail now that was working. Here is the code that calls Chromedriver.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
 
options = Options()
options.add_argument("--headless")
options.add_argument("window-size=398,256")
browser = webdriver.Chrome(executable_path=r'C:\Python\Scripts\chromedriver.exe', options=options)
browser.get('C:\DevCode\Label\Label_Formater.html')
browser.save_screenshot("c:\DevCode\Label\Label.png")
browser.close()
Ideas? Thanks
Through a cloudy window,
Kip...

“Progress means getting nearer to the place you want to be. And if you have taken a wrong turn, then to go forward does not get you any nearer.
If you are on the wrong road, progress means doing an about-turn and walking back to the right road; and in that case the man who turns back soonest is the most progressive man.” ― C.S. Lewis
Reply
#2
Just ran each line one by on in the Python 3.6 command window and it ran without error (including Chromedriver returning True).
But the same code in the Python 3.6 IDE returns the error above.

This is getting stranger and stranger!
Through a cloudy window,
Kip...

“Progress means getting nearer to the place you want to be. And if you have taken a wrong turn, then to go forward does not get you any nearer.
If you are on the wrong road, progress means doing an about-turn and walking back to the right road; and in that case the man who turns back soonest is the most progressive man.” ― C.S. Lewis
Reply
#3
You can not open a local path in browser.get like that.
The simplest way to get correct path to use in browser is to drag and drop Label_Formater.html into browser address bar.
So if a drop a file i will get a address like this.
file:///E:/div_code/index.html
When working with Selenium run code from command line and not IDLE(as it can block).
Reply
#4
(Mar-25-2020, 03:27 PM)snippsat Wrote: When working with Selenium run code from command line and not IDLE(as it can block).

Thanks snippsat,
If the above is true then I'm guessing that my plan to include that code in a function for a Python app is not going to fly at all.

The code I shared, I was planning on building a function to call inside my label app. Am I off track trying to do that using Selenium?
Through a cloudy window,
Kip...

“Progress means getting nearer to the place you want to be. And if you have taken a wrong turn, then to go forward does not get you any nearer.
If you are on the wrong road, progress means doing an about-turn and walking back to the right road; and in that case the man who turns back soonest is the most progressive man.” ― C.S. Lewis
Reply
#5
(Mar-25-2020, 03:32 PM)KipCarter Wrote: If the above is true then I'm guessing that my plan to include that code in a function for a Python app is not going to fly at all.

The code I shared, I was planning on building a function to call inside my label app. Am I off track trying to do that using Selenium?
I see can't see why that should not work.
Can build in function/class and also import for use if that's needed.
Can also build it stand alone with pyinstaller

A test to to run a local html file and take screenshot.
# screenshot.py
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument("--headless")
options.add_argument("window-size=398,256")
browser = webdriver.Chrome(executable_path=r'C:\cmder\bin\chromedriver.exe', options=options)
browser.get('file:///E:/div_code/scrape/sel_screenhot/image.html')
browser.save_screenshot("image.png")
browser.close()
When i say run from command line then is this what i mean, i use cmder as cmd or PowerShell make my sick Sick
E:\div_code\scrape\sel_screenhot
# list files
λ ls
image.html  image.png  screenshot.py

E:\div_code\scrape\sel_screenhot
# Run script
λ python screenshot.py
image.png:
[Image: mhBMOK.png]
image.html:
Output:
<!DOCTYPE html> <html> <body> <h2>Images on Another Server</h2> <img src="https://www.w3schools.com/images/w3schools_green.jpg" alt="W3Schools.com" style="width:104px;height:142px;"> </body> </html>
Reply
#6
I found the issue (or I think I did). I was forced to reboot my laptop while working from home and apparently the remote GPO hammered my Python IDLE 3.6., effectively disabling it. My guess is when I am able to boot on the network it will be fine.

I didn't run your test, but after you said what you did I became very suspicious of the IDLE so I tried to launch it manually with no code and go the very same error.

With that bit of knowledge, I launched my Label_Image from the command line using "Python Label_Image.py" and it ran without error. Then checked the output (Label.png) and it had captured the html rendering perfectly.

I only have today to work from home before I go back into the office (hopefully), so I will just have to fashion things so I can test by running python from the command line.

Thanks for the input Snippsat!
Through a cloudy window,
Kip...

“Progress means getting nearer to the place you want to be. And if you have taken a wrong turn, then to go forward does not get you any nearer.
If you are on the wrong road, progress means doing an about-turn and walking back to the right road; and in that case the man who turns back soonest is the most progressive man.” ― C.S. Lewis
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ChromeDriver breaking Python script genericusername12414 1 314 Mar-14-2024, 09:39 AM
Last Post: snippsat
  Is chromedriver detectable by heavy seured websites? kolarmi19 4 1,489 Mar-29-2022, 08:14 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020