DPC_Watchdog_Violation when ever I try running my code - python

from selenium import webdriver
driver = webdriver.Chrome("C:\Program Files (x86)\chromedriver.exe")
driver.get("https://www.facebook.com/")
After a minute of running that code i get the DPC_Watchdog_Violation error, I made sure I had the right chrome version for chrome-driver, I also tried a different chrome version that goes with chrome driver but still same error.

Try running the selenium with Firefox + geckodriver combination. It worked for me and didn't crash a single time. Seems that chromedriver has a bug in it or something.
Here are some useful links to getting the correct driver version:
Correct driver version table
Driver downloads
Selenium also has an IDE which has very useful functions like action recordings. I highly recommend it as you can export python files from it and then use the generated commands without having to find all of the ids/classes.

Related

How to solve Selenium WebDriver Error using Python?

I am learning Python to tried to do an extraction of data from another website. However, I wrote a simple code to try to open a Chrome browser window and display google on my web browser.
I have seen in other videos that it is only needed to write the following code to get this to work:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://www.google.com")
However, when I try to run it on my PyCharm, I got plenty of error lines. The same happen if I try to run it through my command prompt (both stating the same error - pictures below). I do not know what I am missing, but I should mention that I have downloaded the packages pip, selenium, selenium-chromedriver and I have also downloaded ChromeDriver separetely from the website https://chromedriver.chromium.org/
Could anyone please guide me through this issue? Thanks a lot everyone for your precious help and your time!
Kind regards,
Salvador
ChromeDriver_executable_location
Command_prompt
Python_codeError1
Python_codeError2
Packages_installed
Please post the errors so we can see what it is tell you is wrong.
I am also new to selenium and learning python.
First, make sure your Chromedriver is located in the same folder as your script.
Second, make sure your version of Chrome and Chromedriver are compatible.
Also, when the script is finish it will close the browser immediately.
I ran your posted code and it works for me. Did you have any errors when installing the packages?
I'm not sure why you get an error, but I know a workaround that might work for you.
Instead of using the webdriver file, you can use a service to install it for you, like this:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
You need to install the webdriver_manager library first using pip
Hope this helps
You could place the Chromedriver in system path and try to execute.
Go to Advanced System Settings.
Click on Environment variables.
Select Path variable and click on Edit.
Add the Chromedriver folder path.
Suppose the path for chromedriver.exe file is - C:/project/Chromedriver/chromedriver.exe, place C:/project/Chromedriver in the Path variable.
Restart the computer and then try to execute below lines:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://www.google.com")

Fake webcam chrome option when used with python selenium webdriver

I did not get a specific chrome option to work fine, when started chrome per python selenium webdriver script.
The goal is to start chrome in a python selenium script with a fake webcam, which plays a video file.
The problematic options are "use-file-for-fake-video-capture" combined with "use-fake-device-for-media-stream":
options.add_argument("--use-fake-device-for-media-stream")
options.add_argument("--use-file-for-fake-video-capture=C:\Testfiles\videofiles\bus_cif.y4m")
Both Options are working totally fine used in a batch-file with chrome.exe. For example, the following batch is working fine and used fake webcam videofile:
"C:\Program Files\Google\Chrome\Application\chrome.exe" --use-fake-device-for-media-stream --use-file-for-fake-video-capture=C:\Testfiles\videofiles\bus_cif.y4
Also, the rest of my python chrome webdriver script options are working fine, so the code itself should be correct. For example, the following options are working fine:
options.add_argument("--allow-file-access-from-files")
options.add_argument("--use-fake-ui-for-media-stream")
options.add_argument("--disable-infobars")
Chrome 97.x (with newest stable chromium webdriver files)
Is there something special about the option "use-file-for-fake-video-capture" when used in a python script with options? Or perhaps the path have to be in another format?
Thanks a lot!
Figured it out. Spent hours yesterday, but today shortly after posting to stackoverflow, I found the solution myself:
Problem is the path I used:
Windows path in Python
When using the following, everything works fine and fake video is used even when chrome is started by python script:
options = Options()
options.add_argument("--use-fake-ui-for-media-stream")
options.add_argument("--use-fake-device-for-media-stream")
options.add_argument(r'--use-file-for-fake-video-capture=C:\Testfiles\videofiles\bus_cif.y4m')
self.driver = webdriver.Chrome(options=options)
Important is the r' when using windows path with backslashes. I think the other solution would be using slash instead of backslash.

Selenium webdriver is opening the browser, but not opening the given url

This is the screenshot of the error I'm getting.
I have recently taken up the task to learn functional testing and web automation using selnium webdriver with python. When I execute my code, the web browser opens up, but the URL doesn't. I have tried all the suggestions on the internet such as: updating chrome, trying a different IDE, using FireFox. None of these have helped my code carry out what I want.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
chrome = webdriver.Chrome(executable_path='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome')
chrome.get('https://www.youtube.com/watch?v=oM-yAjUGO-E')
For anyone encountering this issue, please make sure that you have installed the chromedriver (or whatever driver is available for your browser). For chrome you first need to check your information and find out the version from chrome://version/
then from, https://sites.google.com/a/chromium.org/chromedriver/downloads
download the corresponding driver and copy the filepath into the the executable_path section.
Ensure you have installed chromedriver.
The install path would typically be "/usr/local/bin", although whatever the path, that's the one to use as "executable_path"
Also remember to keep Chrome browser and chromedriver versions in sync i.e. if you have Chrome version 81, you should install chromedriver version 81.
I also have encountered this trouble. Before that, you're supposed to check the status code of your access. If it is 400, this station may set anti reptile which preventing any operation of reptile. I solved that by adding following code:
chrome.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": """
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
"""
})

Spyder randomly fails to locate chromedriver

I am using python via spyder to do some web scraping. My code seems to be working fine, but after a few times I open and close chromedriver during the same session of spyder, when I run
from selenium import webdriver
browser = webdriver.Chrome(executable_path = 'C:/Python34/Scripts/chromedriver.exe')
I get the error message
WebDriverException: 'chromedriver.exe' executable needs to be available in the path.
I tried downloading the latest version of chromedriver, but the issue persists. The suggestion I found here says to download the 64bit version of chromedriver, but I was not able to get a hold of that. Is this solvable anyhow? Any help much appreciated.
UPDATE:
Using chromedriver, this was solved using quit() instead of close() to end each session of chrome.
Try:
browser = webdriver.Chrome("C:/Python34/Scripts/chromedriver.exe")

How do I install ChromeDriver on Windows 10 and run Selenium tests with Chrome?

We have an Ubuntu server which we use for running Selenium tests with Chrome and Firefox (I installed ChromeDriver) and I also want to run the tests locally on my Windows 10 computer. I want to keep the Python code the same for both computers. But I didn't find out how to install the ChromeDriver on Windows 10? I didn't find it on the documentation [1, 2].
Here is the code that runs the test in Chrome:
import unittest
from selenium import webdriver
class BaseSeleniumTestCase(unittest.TestCase):
...
...
...
...
def start_selenium_webdriver(self, chrome_options=None):
...
self.driver = webdriver.Chrome(chrome_options=chrome_options)
...
I also found How to run Selenium WebDriver test cases in Chrome? but it seems to be not in Python (no programming language is tagged, what is it?)
Update #1: I found some Python code in https://sites.google.com/a/chromium.org/chromedriver/getting-started, but where do I put the file in Windows 10 if I want to keep the same Python code for both computers?
Update #2: I downloaded and put chromedriver.exe in C:\Windows and it works, but I didn't see it documented anywhere.
As Uri stated in the question, under Update #2, downloading the latest release of chromedriver and placing it in C:\Windows corrects the issue.
I had the same issue with Chrome hanging when the browser window opens (alongside a command prompt window).
The latest drivers can be found at:
https://sites.google.com/chromium.org/driver
The version in the chromedriver_win32.zip file is working on my 64-bit system.
Download the chromedriver.exe and save it to a desired location
Specify the executable_path to its saved path
The sample code is below:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('headless')
driver = webdriver.Chrome(executable_path="path/to/chromedriver.exe", chrome_options=options)
driver.get("example.html")
# do something here...
driver.close()
As Uri stated in Update #2 of the question, if we put the chromedriver.exe under C:/Windows, then there is no need to specify executable_path since Python will search under C:/Windows.
Let me brief out the requirements first.
You need to download the chrome web driver zip from here. https://chromedriver.storage.googleapis.com/index.html?path=2.33/
Extract the file and store it in a desired location.
Create a new project in Eclipse and include the following code in your class.
System.setProperty("webdriver.chrome.driver", "C:\\temp\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
Explanation : System.setProperty(key,value):
Key is default and same for all the systems, value is the location of your chromedriver extract file.

Categories