I am learning python and I am running into an issue
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://www.google.com')
my firefox launches but it does not go on google.com like it is supposed to be but rather stays as a blank page.
I would recommend using chrome instead because your script does work.
so... http://chromedriver.storage.googleapis.com/2.9/chromedriver_win32.zip Download that and extract it to your python27/scripts folder located in the root directory in the C:\\ Drive and then run this script.
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://www.facebook.com')
And It should connect you to facebook.com Hope I helped. :)
Related
How do I navigate and click buttons on an already open Chrome instance/window. So the scenario is, that an application named "ApplicationNAME" is installed on my Windows machine, but its not a Windows application, because when I run the application it is only opening a chrome instance (not the default Chrome browser). I am also able to see the Developers Tool of chrome, and I am able to inspect the elements which means a chrome instance is opened.
So the idea is to automate this Application using Python and Selenium. I am open for alternate suggestions too. Thank you!
I have used the below Python (3.7.3) code but it doesn't help, because it rather opens another Chrome browser or navigate to already open Chrome window rather than going into the desired "ApplicationNAME" chrome instance.
from pywinauto.application import Application, WindowSpecification
import time
import requests
import selenium
from selenium import webdriver
app = Application().start(cmd_line=u'"C:\\Program Files (x86)\\ApplicationName.exe" ')
chromewidgetwin = app[u'ApplicationName']
chromewidgetwin.wait('ready')
chromerenderwidgethosthwnd = chromewidgetwin[u'Chrome Legacy Window']
chromerenderwidgethosthwnd.click()
Driver = webdriver.Chrome ("C:\\chromedriver.exe")
Driver.switch_to_window('ApplicationName')
I was trying to do something with a gecko driver ( Selenium in this case ) and I can't get my chrome driver to work. Knowing that I am on Mac Sierra, and that my script is in the same folder as my chrome driver, here is my code
from selenium import webdriver
import time
url = "https://accounts.google.com/signup/v2/webcreateaccount?flowName=GlifWebSignIn&flowEntry=SignUp"
driver = webdriver.Chrome("chromedriver")
driver.get(url)
Thanks for the help
You can test if it actually is in the PATH, Open your command prompt go to the location of your chromedriver and hit enter. you will get below message:
C:\>
chromedriver.exe
Starting ChromeDriver 76.0.3809.68 (420c9498db8ce8fcd190a954d51297672c1515d5-ref
s/branch-heads/3809#{#864}) on port 9515
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent
access by malicious code.
Then you need to setup PATH like below before you start your test:
driver = webdriver.Chrome('/path/to/chromedriver')
Try this:
from selenium import webdriver
driver= webdriver.Chrome(executable_path="C:/users/usr/Desktop/chromedriver.exe")
url = 'your website'
driver.get(url)
make sure you are using this slash (/) in your file path to the chrome driver (as shown above)
im trying to load a specific chrome profile using Python selenium webdriver, but i cant interact with the driver after assigning the chrome profile. it opens the chrome profile that i wanted, but from there - nothing. i cant do any action. for example - im trying to open Microsoft.com:
This works:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://www.microsoft.com')
But this doesnt work at all:
from selenium import webdriver
import getpass
username = getpass.getuser()
options = webdriver.ChromeOptions()
options.add_argument('user-data-dir=C:/Users/'+username+'/AppData/Local/Google/Chrome/User Data/')
driver = webdriver.Chrome(executable_path='C:/Users/'+username+'/Documents/selProject/chromedriver.exe', chrome_options=options)
driver.get('http://www.microsoft.com')
The above code opens chrome, but doesnt go to microsoft.com or any other action.
thanks for reading!
This is likely because you have Chrome open already with that user signed in.
In order to use chrome with that profile, while also running the script you'll need to separate the directories where the profiles are pulled from. That is, move (or copy) the Default profile to another directory that you call to within the user-data-dir argument.
You do following things and check whether it works.
Upgrade python bindings using
pip install -U selenium
for chrome browser download the latest chrome driver "ChromeDriver 2.45"
form http://chromedriver.chromium.org/downloads and write the code
from selenium import webdriver
driver=webdriver.Chrome("Path of the Chromedriver" + "chromedriver.exe" )
driver.get('http://www.microsoft.com')
I have tried searching the official documentation, but no result. Does Chrome Web Driver needs to be in client's system for a python script using Selenium to run? I basically want to distribute compiled or executable file versions of the application to the end user. How do i include Chrome Web driver with that package?
Yes you will have to download and put chromedriver to your system and then need to call in selenium code.
Download chromedriver from here : Chromedriver for selenium
Below code will help you to call chrome driver using selenium with python :
import os
from selenium import webdriver
chromedriver = "/Users/mike/Downloads/chromedriver" [you please put your actual path of chrome driver]
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
Hope this help you.
If you are using selenium RC , then you can set path like below :
selenium = new DefaultSelenium(Server, ServerPort, "*googlechrome", DomainURL);
chromedriver needs to be installed on the machine that will launch the instance of the Chrome browser.
If the machine that launches the Chrome instance is the same machine as where the Python script resides, then the answer to your question is "yes".
If the machine that launches the Chrome instance is a machine different from the machine that runs your Python script, then the answer to your question is "no".
I'm trying to use selenium from python but I'm having a problem running it on a RHEL5.5 server. I don't seem to be able to really start firefox.
from selenium import webdriver
b = webdriver.Firefox()
On my laptop with ubuntu this works fine and it starts a brings up a firefox window. When I log in to the server with ssh I can run firefox from the command line and get it displayed on my laptop. It is clearly firefox from the server since it has the RHEL5.5 home page.
When I run the python script above on the server it (or run it in ipython) the script hangs at webdriver.Firefox()
I have also tried
from selenium import webdriver
fb = webdriver.FirefoxProfile()
fb.native_events_enabled=True
b=webdriver.Firefox(fb)
Which also hangs on the final line there.
I'm using python2.7 installed in /opt/python2.7. In installed selenium with /opt/python2.7/pip-2.7.
I can see the firefox process on the server with top and it is using a lot of CPU. I can also see from /proc/#/environ that the DISPLAY is set to localhost:10.0 which seems right.
How can I get a browser started with selenium on RHEL5.5? How can I figure out why Firefox is not starting?
It looks like the problem I'm encountering is this selenium bug:
http://code.google.com/p/selenium/issues/detail?id=2852
I used the fix described in comment #9 http://code.google.com/p/selenium/issues/detail?id=2852#c9
That worked for me.