Unable to display website on chrome when ran the program - python

I had recently started learning automation with python using selenium. I had installed chromedriver but when i run the code chrome displays no output. My code:
from selenium import webdriver
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("www.wikipedia.com")
Output
Output :
C:\Users\Admin\PycharmProjects\untitled\venv\Scripts\python.exe C:/Users/Admin/PycharmProjects/untitled/1.py
Traceback (most recent call last):
File "C:/Users/Admin/PycharmProjects/untitled/1.py", line 5, in <module>
driver.get("www.wikipedia.com")
File "C:\Users\Admin\PycharmProjects\untitled\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "C:\Users\Admin\PycharmProjects\untitled\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Admin\PycharmProjects\untitled\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
(Session info: chrome=88.0.4324.96)
Please help as I'm unable to proceed.
Thanks!

URL should contain scheme. Simply replace
"www.wikipedia.com"
with
"https://www.wikipedia.com"

Related

Unable to store a function in a variable in Selenium

Okay so I was writing my first selenium code which is:
browser.get('https://www.jetbrains.com/pycharm/')
browser.find_element_by_link_text('Download')
<selenium.webdriver.remote.webelement.WebElement (session="69f43bf4a5e98baf24ad3746dd01b514", element="0fa96685-d871-464f-aaaa-af02238a5f08")>
I wanted to simply go to the pycharm website and click on downloads, which worked fine.
But when I tried to store the previous function in a variable like so:
elem = browser.find_element_by_link_text('Download')
I got all these errors:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 428, in find_element_by_link_text
return self.find_element(by=By.LINK_TEXT, value=link_text)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
'value': value})['value']
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchWindowException: Message: no such window: window was already closed
(Session info: chrome=87.0.4280.66)
I have no idea what they mean or what ive done wrong. Help much appreciated.
PS: I am using pycharm and selenium chromedriver if thats helpful.
No issues in this.
from selenium import webdriver
browser = webdriver.Chrome(executable_path='C:/bin/chromedriver.exe')
browser.get('https://www.jetbrains.com/pycharm/')
element = browser.find_element_by_link_text('Download')
element.click()

Selenium doesnt fetch url (3 lines of python)

Using chrome 76.0.3809.132 with chromedriver 76.0.3809.126 the testing browser opens but throws a traceback on the driver.get. It isn't able to fetch the page.
Tried couple of arguments, and tried looking for an older version of Chrome with an older chrome driver, which seems impossible.
from selenium import webdriver
driver = webdriver.Chrome("C:/chromedriver/chromedriver.exe")
driver.get("www.google.com")
Output:
DevTools listening on ws://127.0.0.1:57577/devtools/browser/7494ca24-60fb-4b14-9aed-4f25232b94bd
Traceback (most recent call last):
File "slidingwindow.py", line 5, in <module>
driver.get("www.google.com")
File "C:\projects\python\harvester\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "C:\projects\python\harvester\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\projects\python\harvester\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument (Session info: chrome=76.0.3809.132)
Try to insert https://:
from selenium import webdriver
driver = webdriver.Chrome(executable_path="chromedriver.exe")
driver.get("https://www.google.com")

Selenium chromedriver 2.25 TimeoutException cannot determine loading status

I am using python3 on mac os and I have updated chrome, chromedriver and selenium to the latest version. I am getting a TimeoutException, the browser opens correctly but it freezes.
>>> from selenium import webdriver
>>> driver = webdriver.Chrome()
# opens browser with blank page
>>> driver.get('http://example.com')
# gets first page OK and then driver literally flashes once
>>> driver.get('http://stackoverflow.com')
>>>
# Cursor loading forever... until TimeoutException
This error is thrown:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 248, in get
self.execute(Command.GET, {'url': url})
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: timeout: cannot determine loading status
from timeout: Timed out receiving message from renderer: -0.003
(Session info: chrome=54.0.2840.71)
(Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.12.0 x86_64)
I'm using: Python 3.5.2 ,Chrome 54.0, chromedriver 2.25, selenium 3.0.1
I've tried other versions of chromedriver with no success, also I did not find any solution to this online. Thanks.
EDIT:
Still getting the error from above + getting a new error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: session not created exception
from unknown error: bad inspector message: {"method":"Page.loadEventFired","params":{"timestamp":14220,088073}}
(Session info: chrome=54.0.2840.71)
(Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.12.0 x86_64)
selenium.common.exceptions.TimeoutException: Message: timeout: cannot determine loading status
from timeout: Timed out receiving message from renderer: -0.003
Issue817:It looks like this issue has been logged as a bug for Selenium.
Someone has answered to get rid from this issue by using the --dns-prefetch-disable option of chrome.
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--dns-prefetch-disable')
driver = Chrome(chrome_options=chrome_options)
If issue still exists follow this thread may be it solves your problem
Set
env LANG=en_US.UTF-8 ./chromedriver
from : https://bugs.chromium.org/p/chromedriver/issues/detail?id=1552

Error Open Urls Selenium From txt File

I m trying to open URLS From TXT file with selenium webdriver.But code is giving me error.Here is code that i m using with python 3.4.3.What can be the problem in this code?
from selenium import webdriver
with open("vps.txt","r") as fi:
urls = fi.read().splitlines()
for url in urls:
browser = webdriver.Firefox()
browser.get(url)
I get this error:
Traceback (most recent call last):
File "C:\pselenium\browse.py", line 8, in <module>
browser.get(url)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 245, in get
self.execute(Command.GET, {'url': url})
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 233, in execute
self.error_handler.check_response(response)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Target URL www.youtube.com/watch?v=DowtrQhvbUM is not well-formed.
Stacktrace:
at FirefoxDriver.prototype.get (file:///C:/Users/naV/AppData/Local/Temp/tmpja7hed7p/extensions/fxdriver#googlecode.com/components/driver-component.js:10636)
at DelayedCommand.prototype.executeInternal_/h (file:///C:/Users/naV/AppData/Local/Temp/tmpja7hed7p/extensions/fxdriver#googlecode.com/components/command-processor.js:12661)
at DelayedCommand.prototype.executeInternal_ (file:///C:/Users/naV/AppData/Local/Temp/tmpja7hed7p/extensions/fxdriver#googlecode.com/components/command-processor.js:12666)
at DelayedCommand.prototype.execute/< (file:///C:/Users/naV/AppData/Local/Temp/tmpja7hed7p/extensions/fxdriver#googlecode.com/components/command-processor.js:12608)
Target URL www.youtube.com/watch?v=DowtrQhvbUM is not well formed
It looks like you've got a problem with your file encoding. I'm not sure if that's the BOM or not, but you should check your file with a hex editor.

Python Splinter issue

I just installed Splinter, input simple code like below but have error. Can someone help me on this? Thanks.
from splinter import Browser
b=Browser()
url = "http://www.google.com"
b.visit(url)
Error messages:
Traceback (most recent call last): File "", line 1, in
File
"/usr/local/lib/python2.7/dist-packages/splinter/driver/webdriver/init.py",
line 184, in visit
self.driver.get(url) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",
line 245, in get
self.execute(Command.GET, {'url': url}) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",
line 233, in execute
self.error_handler.check_response(response) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py",
line 194, in check_response
raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: Target URL
www.google.ca is not well-formed. Stacktrace:
at FirefoxDriver.prototype.get (file:///tmp/tmpsIlz0H/extensions/fxdriver#googlecode.com/components/driver-component.js:10636)
at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmpsIlz0H/extensions/fxdriver#googlecode.com/components/command-processor.js:12661)
at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmpsIlz0H/extensions/fxdriver#googlecode.com/components/command-processor.js:12666)
at DelayedCommand.prototype.execute/< (file:///tmp/tmpsIlz0H/extensions/fxdriver#googlecode.com/components/command-processor.js:12608)
Try this instead:
from splinter import Browser
with Browser() as b:
b.visit("http://www.google.com")
Docs here: https://splinter.readthedocs.org/en/latest/#sample-code
The method above handles quitting the browser. Your method, also in the docs, should work (it works for me). Try it again, I've noticed I get almost the same error as yours, if my url is "www.google.com". Make sure you have "http://" part.
selenium.common.exceptions.WebDriverException: Message: Target URL
www.google.com is not well-formed

Categories

Resources