I keep getting this error:
https://sites.google.com/a/chromium.org/chromedriver/help/chromedriver-crashes
I get it when running the command:
python Web.py
However when I go into the file and run the lines 1 by 1, I don't get the error. However I always get the error when the Web.py file has finished. When I run the lines 1 by 1, it's very basic things but i feel like I"m not ending my script correctly.
import selenium
from selenium.webdriver.common.keys import Keys
import time
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('espn.com')
I want the window with espn.com to stay on the screen, not quit when the script has finished.
I'm running this on Python. I can share my setup, maybe that's something I did incorreclty but any help would be appeciated.
You're passing an invalid url.
You need to pass the url like this:
driver.get("http://www.espn.com")
This might work in your browser, but it won't with selenium. Type in "espn.com" in your browser and then copy / paste the url and you'll see that it's actually the above url.
You should also specify the "chromedriver.exe" path.
You are getting this error because you had not installed the chrome driver for selenium on your Machine. Selenium by default provides the driver for Firefox so when you use the webdriver for Firefox, it won't rise any error. To resolve this issue with Chrome you can download the Chrome webdriver from here.
and you can specify the driver as
from selenium import webdriver
d = webdriver.Chrome(executable_path='<your Chrome driver path>')
Adding to what #Pythonista said , it's better if you keep the URL as a raw string than a normal string
driver.get(r'http://www.espn.com')
so that it won't take the slash as an escape sequence in few cases.
Hope it helps.
Try to update chrome and get updated/latest chrome driver, recently chrome made several updates in its driver you can download the last one from the link below:
https://chromedriver.storage.googleapis.com/2.27/chromedriver_win32.zip
Related
I'm trying to create a script for scraping some websites. However, I am unable to move past the very first step, since .get method returns 'None' value for any website I try.
This is how my code looks like:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
options = Options()
options.headless = True
options.add_argument("--window-size=1920,1200")
s=Service('D:/Downloads/chromedriver.exe')
driver = webdriver.Chrome(service=s,options=options)
print(driver.get("https://www.tutorialspoint.com/about/about_careers.htm/"))
driver.quit()
Here's what I have already tried:
Made sure the latest version of Selenium is installed;
Made sure that my chromedriver's version is the same as Chrome's -- both are 107;
Added the services bit, as before adding that, I would get an error saying: 'DeprecationWarning: executable_path has been deprecated, please pass in a Service object';
Tried to move chromedriver.exe to Chrome/Applicatiom folder and even my project folder, both did not work.
NB, the above website is just some random example, I've tried many websites and all of them return 'None'. Also, I cannot use bs4 for the websites I want to scrape, so that is not an option.
Any ideas on what I'm missing?
OS: Windows 10
Browser: IE11
Selenium (Python) package: 3.0.1
IEWebDriverServer.exe: 3.1.0
We are getting ready to migrate our automation nodes to Windows 10 and during our tests, we found that although our scripts work fine on Win7 on FF, IE, and Chrome, they fail on Windows 10 only for IE (works fine for FF and Chrome).
When running agianst IE, the browser instantiates and webdriver is able to see the browser (I tried a simple command such as driver.back() which returns to previous page). However, we cannot get any find_element... calls to work. Whether it be by id, name, css, xpath, etc. The script will just fail stating that no element was found for the given id/name/css/xpath (whatever method I tried to use to find the webelement).
I have seen posts regarding security updates that broke this and suggesting to revert the update. This was a year ago though and it seems subsequent updates have fixed this issue.
I have also read posts about making sure the protected mode is the same across all zones, a registry value, etc. None of these suggestions have worked though.
Here is the sample script I am using which (when modified to run in Chrome or Firefox passes) does not work in IE11 only:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Ie()
driver.implicitly_wait(30)
driver.maximize_window()
# navigate to the application home page
driver.get("http://www.google.com")
# get the search textbox
search_field = driver.find_element_by_id("lst-ib")
The error from running this script is:
selenium.common.exceptions.NoSuchElementException: Message: Unable to find element with id == lst-ib
Although I'm sure you not that bothered now, I logged the same issue a few days ago and I'm still stuck (click here). I have further narrowed down the problem to security. If you increase logging you will see the below lines:
W 2017-03-06 17:27:41:539 Script.cpp(494) -2147024891 [Access is denied.]: Unable to execute code, call to IHTMLWindow2::execScript failed
W 2017-03-06 17:27:41:540 Script.cpp(180) Cannot create anonymous function
W 2017-03-06 17:27:41:540 ElementFinder.cpp(98) A JavaScript error was encountered executing the findElement atom.
I have tried every security option on/off but to no avail. I'm getting the problem locally and haven't set up my CI environment so hoping that when i spin it up it should just work (fingers crossed).
P.S. I don't think you had a broken VM!!
Whenever I stumble across a 'NoSuchElementException' (albeit not on Windows or IE), this has always worked:
Add these imports:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
Then to locate the element:
search_field = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, """//*[#id="lst-ib"]""")))
search_field.send_keys('Example')
Credit to Web Scraping with Python. I hope this helps, although at the moment I don't have windows or IE to verify this in advance.
I am writing a python script which includes opening up an URL and do some activity on it. I am facing an issue when i execute below code then Firefox browser starts but it is not able to browse URL. What could be wrong here..?
I also tried to add proxy exception but that isn't solve issue.
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('WEBSITE_URL')
So, Pls suggest what is wrong here.
I am facing issue with Python web driver. I am able to launch the browser through webdriver and open required URL and login, but issue comes later when I try to find object of any element present on screen, it waits for long time(some times 30 min to 1 hr) to get web element. I have tried creating profile as given below, but still result is same.
fp = webdriver.FirefoxProfile()
fp.set_preference("webdriver.load.strategy", unicode("unstable")).
self.browser = webdriver.Firefox(fp)
Do any 1 know solution for this?
Note: It works fine on Chrome.
Thanks for your help..
I am using selenium. I have the following code:
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
browser = webdriver.Firefox()
browser.get("http://www.mysite.com")
x = browser.find_elements_by_xpath("//div[#id='containeriso3']/div/a[1]")
hrefs = [i.get_attribute('href') for i in x]
Now, this works.
But I want to do this is on a server which runs on ubuntu command line. This means I cannot use this
browser = webdriver.Firefox()
in my code. What alternative can be used to this through command line?
You can use HtmlUnitDriver which is headless browser based on Rhino javascript engine.
http://code.google.com/p/selenium/wiki/HtmlUnitDriver
If your Ubuntu server and your desktop are on the same network use Selenium Grid. Your code will start on the Linux server and your tests will be executed on your desktop.
Take a look at the following link:
http://code.google.com/p/selenium/wiki/Grid2
The examples are in Java but I'm sure you can adapt them to Python or at least get the idea of what you need to do.
I think you can also try to use ghost driver that is based on phantomjs:
https://github.com/detro/ghostdriver, or you can also try to run usual firefox driver on Xvfb.
It depends on what you need.