PyAutoGUI WindowsError: [Error 5] - python

I am working with PyAutoGUI in Python 2.7 using PyCharm and am getting a permissions error. Here is my code:
import pyautogui
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# Open the browser.
browser = webdriver.Firefox()
browser.maximize_window()
# Click on the address bar.
pyautogui.click(x=150,y=50)
# Fill in the URL.
pyautogui.typewrite('yahoo.com')
The windows is opening and maximizing just fine and the mouse is moving and clicking (I tried the code on my IDE and it moved and clicked the top toolbar), but alas, nothing is being typed. How do I fix the permissions so that I can click and type?
NOTE: The script DOES work when run from the command line.
Thanks.

This issue should be solved in 0.9.34, so you just need to update PyAutoGUI by running pip install -U pyautogui.

Related

Chromium Webdriver with "--no-sandbox" is opening a fully transparent/invisible Chrome window

The relevant code is as follows:
# find the Chromium profile with website caches for the webdriver
chrome_options = Options()
profile_filepath = "user-data-dir=" + "/home/hephaestus/.config/chromium/Profile1"
chrome_options.add_argument(str(profile_filepath))
# put chromium into --no-sandbox mode as a workaround for "DevToolsActivePort file doesn't exist"
chrome_options.add_argument("--no-sandbox")
# start an automatic Chrome tab and go to embervision.live; wait for page to load
driver = webdriver.Chrome("./chromedriver", options=chrome_options)
When I run this Python code (and import the needed libraries), I get the screenshot below. Chromium that was opened with the above code is on the right, and is transparent and glitching out.
Desktop view with Chromium webdriver tab glitching out on the right
I am able to enter web addresses and interact with the page, but I just can't see any of it. I'm not sure why.
I deleted and re-downloaded Selenium and Chromium, to no avail. I had to add the "--no-sandbox" option because it was getting another error that said "DevToolsActivePort file doesn't exist".
I'm not sure what else is causing this issue.
So I found a solution that works for me!
Uninstall and reinstall Chromium completely. When reinstalling, check that your Chromium version matches with Selenium (which I didn't even know was a thing).
DO NOT run your Python code as a sudo user. I did "sudo python3 upload_image.py" and got the "DevToolsActivePort file doesn't exist" error. When I ran just "python3 upload_image.py", it did not raise the error.
Do not use the option "--no-sandbox" when running as a non-sudo user ("python 3 upload_image.py"). For some reason, the "--no-sandbox" option also broke my Chromium browser in the same transparent/infinite way as I posted above.
Hope this helps someone in the future!

My selenium script (in Python) for chrome runs but does nothing

vscode says it run but it does nothing. My pip is up to date and i installed selenium with the command prompt. i have a valid path (i think) for chromedriver. Here's my code:
from selenium import webdriver
chromedriver = "C:Users/P-Lou/Downloads/chromedriver.exe"
driver = webdriver.Chrome(chromedriver)
driver.get("http:google.com")
The result is this:
[Running] python -u "w:\Python\Seletest\app.py"
[Done] exited with code=0 in 0.067 seconds
I tried this code by only changing the browser to firefox and removing the chromedriver = part and it worked fine, you might be running the browser in headless mode, thats why nothing pops up. You can change that using The Chromedriver.options(set_headless="false")
(not sure if that is the right code, you can check yourself here)
Presuming the ChromeDriver binary location being C:\Users\P-Lou\Downloads on your windows system you can use the following solution:
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'C:\Users\P-Lou\Downloads\chromedriver.exe')
driver.get("http:google.com")

Page is not loaded in Selenium WebDriver using Python on Windows

I am using Python 3.5 on a Windows computer. When I run this code on my Mac it works perfect, no issues what so ever. But when I bring the code to my Windows computer it doesn't work.
Basically a blank page is shown instead of the home page. I don't get any error messages.
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('https://www.google.com')
cookies = driver.get_cookies()
print(cookies)
Once I close the web browser I get this message in the shell:
"The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
From what I've been able to find online (most is for Java) it looks like I may need to setup a profile? Is this correct and could anyone help with this?
It looks like your client doesn't have the fix for the new switch to launch the gecko driver:
https://github.com/SeleniumHQ/selenium/commit/c76917839c868603c9ab494d8aa0e9d600515371
Make sure that you have the latest beta version installed (selenium-3.0.0b2) if you which to use the geckodriver v0.10.0 and above:
pip install -U selenium --pre
Note that you need the --pre flag to install the beta version.

Python import module only works in a new terminal window

I'm trying to run the following python script:
from selenium import webdriver
driver = webdriver.PhantomJS()
driver.get('https://www.everlane.com/collections/mens-luxury-tees/products/mens-v-antique')
driver.save_screenshot('screen.png') # save a screenshot to disk
print driver.current_url
images = driver.find_elements_by_tag_name('img')
for image in images:
print image.get_attribute('src')
However, every time I try to run it, I get this error:
FitValet-MacBook-Pro:desktop fitvalet$ python selenium.py
Traceback (most recent call last):
File "selenium.py", line 1, in <module>
from selenium import webdriver
File "/Users/fitvalet/Desktop/selenium.py", line 1, in <module>
from selenium import webdriver
ImportError: cannot import name webdriver
FitValet-MacBook-Pro:desktop fitvalet$
But I've installed the module using pip install selenium and it installed fine. When I run a new terminal window, enter python, and then type in from selenium import webdriver, it imports fine. If I exit() python, and then re-enter and try again, the same above error happens, in that it can't import selenium. If I re-open terminal, then it works again, but only in the terminal python window. I can even type out every line of code and it prints the images fine in the terminal!
It never works if I just try to run the script on its own. Any ideas as to why this is? Thanks!!!
WOW. I can't believe this, but my little script, which I so simply named "selenium.py", was the problem. The answer is, DON'T DO THIS! When the script said from selenium import webdriver, it somehow thought it was calling itself, and creating major errors.
I renamed the script to "myselenium.py" and it worked fine.

Firefox won't 'drive' with Selenium webdriver

I've used Firefox with Webdriver on this machine before, but suddenly when I use any code that utilizes Firefox as the driver, Firefox will open and just sit there blankly. Absolutely nothing loads, my program hangs until I close the window at which point it raises the "browser not open" error.
Tried reinstalling. Chrome/IE Drivers work but I don't really want to use them.
Included a pic of exactly what happens when I use any code, for instance
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
url = "http://google.com"
driver.get(url)
Even this gets me nothing.
upgrade to selenium version 2.29.0
pip install -U selenium
there was a bug fix in the previous version

Categories