I input selenium firefox like this in my code,
I am running python 2.7 on windows and using bash with conda
driver = webdriver.Firefox('./firefoxdriver')
This is what my terminal says:
C:\Users\Vinko\Desktop\predictBO-master>bash oakniiv#vinko:/mnt/c/Users/Vinko/Desktop/predictBO-master$ source activate predictboba (predictboba) oakniiv#vinko:/mnt/c/Users/Vinko/Desktop/predictBO-master$ python demotrade_tf.py Traceback (most recent call last): File "demotrade_tf.py", line 99, in <module>
driver = webdriver.Firefox('./firefoxdriver') File "/home/oakniiv/anaconda2/envs/predictboba/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 53, in __init__
self.NATIVE_EVENTS_ALLOWED and self.profile.native_events_enabled) AttributeError: 'str' object has no attribute 'native_events_enabled'
I do not know what else to give you, it looks like the problem is in firefox itself?
It works when I do driver = webdriver.Firefox()
You passed a str as a FirefoxProfile, which is the problem:
driver = webdriver.Firefox('./firefoxdriver')
You want:
profile = webdriver.FirefoxProfile('./firefoxdriver')
driver = webdriver.Firefox(profile)
If you did not intend to use a custom profile, then you can use defaults:
driver = webdriver.Firefox()
Related
I know that Selenium WebDriver might be mostly for testing web apps but I've seen that there is possibility to handle also desktop windows. I have this piece of code:
self._host = "http://localhost:4723"
options = {
"app": "Root",
'deviceName': 'WindowsPC',
'platformName': 'Windows',
}
self.root = webdriver.Remote(self._host, options)
self.root.find_element_by_accessibility_id("Word")
And I want to grab here the window with Word document and then edit it. I am getting error:
Traceback (most recent call last):
File "Test.py", line 77, in test_python_is_python
self.root.find_element_by_accessibility_id("Word")
AttributeError: 'WebDriver' object has no attribute 'find_element_by_accessibility_id'
Any ideas? Because for me it looks exactly like in example.
Thanks!
How to solve NameError:Options is not defined in AWS Lambda ?
my attempts
Added selenium module file in awslambda
aws docuemnt refer. but not solve
stackoverflow errormessage search but not solve.
Then, it worked, but the error occurred (cloudwatch).
2021-06-28T12:30:31.892+09:00 START RequestId: 7bb8408e-2b12-4e16-80be-e6f1b0166a60 Version: $LATEST
2021-06-28T12:30:31.892+09:00 Error in Imports
2021-06-28T12:30:31.895+09:00 [ERROR] NameError: name 'Options' is not defined Traceback (most recent call last): File "/var/task/lambda_function.py", line 203, in lambda_handler instance_ = WebDriver() File "/var/task/lambda_function.py", line 25, in __init__ self.options = Options()
selenium sample code
import json
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
def __init__(self):
self.options = Options()
self.options.binary_location = '/opt/headless-chromium'
self.options.add_argument('--headless')
self.options.add_argument('--no-sandbox')
self.options.add_argument('--start-maximized')
self.options.add_argument('--start-fullscreen')
self.options.add_argument('--single-process')
self.options.add_argument('--disable-dev-shm-usage')
def get(self):
driver = Chrome('/opt/chromedriver', options=self.options)
return driver
my goals
Through aws_lambda, I want to collect data through crawling all day long.
Just had a similar issue so perhaps it can help you:
Check if the selenium, chromdriver $ headless-chromium are zipped properly.
so when you upload it as a layer to aws lambda, it has the right pathname for you to import selenium in your lambda code.
you can download the file chrome_headless.zip from: https://github.com/soumilshah1995/Selenium-on-AWS-Lambda-Python3.7
and then zip it again inside that folder, on your local machine:
zip -r chrome_headless.zip chromedriver headless-chromium python
then try to upload it to aws lambda layers, attach it to your function and test it.
all credit goes to Soumil Nitin Shah with his great tutorial:
https://www.youtube.com/watch?v=jWqbYiHudt8
I want to use the chrome webdriver to connect to "https://www.google.com".
below is the code.
from selenium import webdriver
import time
driver = webdriver.Chrome("C:\\Users\\faisal\\library")
driver.set_page_load_timeout(10)
driver.get("https://www.google.com")
driver.find_element_by_name("q").send_keys(" automation by name ")
driver.find_element_by_name("blink").click()
time.sleep(5)
driver.close()
When I run the test, the following error message is displayed.Its a permission problem
C:\Users\faisal\PycharmProjects\firstSeleniumTest2\venv\Scripts\python.exe C:/Users/faisal/PycharmProjects/firstSeleniumTest2/test.py
Traceback (most recent call last):
File "C:\Users\faisal\PycharmProjects\firstSeleniumTest2\venv\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Python\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Python\lib\subprocess.py", line 997, in _execute_child
startupinfo)
PermissionError: [WinError 5] Access is denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/faisal/PycharmProjects/firstSeleniumTest2/test.py", line 4, in <module>
driver = webdriver.Chrome("C:\\Users\\faisal\\library")
File "C:\Users\faisal\PycharmProjects\firstSeleniumTest2\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__
self.service.start()
File "C:\Users\faisal\PycharmProjects\firstSeleniumTest2\venv\lib\site-packages\selenium\webdriver\common\service.py", line 88, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'library' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Process finished with exit code 1
The error says it all :
selenium.common.exceptions.WebDriverException: Message: 'library' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
In you code block you mentioned :
driver = webdriver.Chrome("C:\\Users\\faisal\\library")
The error clearly says your program was considering library as the ChromeDriver binary. Hence the error.
But as per the documentation of selenium.webdriver.chrome.webdriver the call to the WebDriver() is as :
class selenium.webdriver.chrome.webdriver.WebDriver(executable_path='chromedriver', port=0, options=None, service_args=None, desired_capabilities=None, service_log_path=None, chrome_options=None)
So you need to change send the Key executable_path along with the Value as the absolute path within single qoute '' along with the raw (r) switch as follows :
driver = webdriver.Chrome(executable_path=r'C:\Users\faisal\library\chromedriver.exe')
Update
As per the counter question from #Mangohero1 of-coarse executable_path is optional but in case you provide only the absolute path as per the source code provided below the absolute path is considered as the Value to the Key executable_path.
class WebDriver(RemoteWebDriver):
"""
Controls the ChromeDriver and allows you to drive the browser.
You will need to download the ChromeDriver executable from
http://chromedriver.storage.googleapis.com/index.html
"""
def __init__(self, executable_path="chromedriver", port=0,
options=None, service_args=None,
desired_capabilities=None, service_log_path=None,
chrome_options=None):
"""
Creates a new instance of the chrome driver.
Starts the service and then creates new instance of chrome driver.
:Args:
- executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
C:\Users\faisal\library is not the correct path to chromedriver. Give the actual path to your chromedriver file.
In case of Linux providing permission will solve the problem.
Use
sudo chmod +x chromedriver
driver=webdriver.Chrome("C:\\Users\\SQA Anas\\Downloads\\chromedriver.exe")
Please enter the complete chrome driver path like this:
"C:\Users\SQA Anas\Downloads\chromedriver.exe"
Its works for me :)
The executable_path should have chromedriver added at last:
executable_path='/home/selenium/Linkedin-Automation/chromedriver'
I had to use the following to run on Windows 10 64 bit and 32 bit chromedriver:
driver = webdriver.Chrome(executable_path=r'C:\\Users\\My Name\\Downloads\\chromedriver_win32\\chromedriver.exe')
I am trying to implement page object model in python and selenium. For that matter, I have two modules:
LoginPage.py
class LoginPage:
def __init__(self, driver):
self.driver = driver
'''do something with the self.driver object.
Example: Using self.driver.title() I can make sure if I am on the right page but it shows an error'''
def Login(self, username, password):
'''Use the same driver object for calling username and password objects of a page'''
Program.py
from selenium import webdriver
from LoginPage import *
class Program:
driver = webdriver.Firefox()
driver.get("https://www.linkedin.com/uas/login")
#While creating LoginPage object, I'm passing driver object which is actually a firefox instance.
login = LoginPage(driver)
homePage = login.Login("sample#gmail.com", "mypassword")
if homePage is not None:
print "In Home page"
From the Program.py module, I am creating a Firefox driver and passing the reference to 'driver'. This 'driver' is passed as a parameter to LoginPage().
The LoginPage.py is not able to make use of 'driver'. Can anyone help me find the mistake here?
Traceback:
Traceback (most recent call last):
File "/media/Pinku/POMProject/src/Program.py", line 4, in <module> class Program:
File "/media/Pinku/POMProject/src/Program.py", line 11, in Program login = LoginPage(driver)
File "/media/Pinku/POMProject/src/LoginPage.py", line 5, in init if self.driver.title() == "Sign In":
TypeError: 'unicode' object is not callable
Right I see your problem:
It's very simple, in your __init__ in LoginPage you are calling self.driver.title() however, as per the basic selenium example on their page, it is just self.driver.title (without the brackets).
title is an attribute rather than a callable method, hence the error.
I looked at number of examples as well as source code for ActionChains and seemingly am using the code suggested in other examples for hover functionality, but still I cannot get over this exception. The code is as follows:
menu = browser.find_element_by_xpath("//nav/ul/li/a[#href='#'][.='Profile']")
hover = ActionChains(webdriver).move_to_element(menu)
hover.perform()
and the exception is:
Traceback (most recent call last):
File "./test.py", line 56, in <module>
hov.perform()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/action_chains.py", line 44, in perform
action()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/action_chains.py", line 201, in <lambda>
self._driver.execute(Command.MOVE_TO, {'element': to_element.id}))
AttributeError: 'module' object has no attribute 'execute'
At first, I thought it was not working because there is no id attribute on the element, however I confirmed that is not the case (find_element_by_xpath does return correct element and there is some sort of {unique id} assigned to it). My Python skills are quite elementary, but I need to adapt the testing script I working on. I am sure I just don't understand this error.
Thanks for your help!
The first argument to ActionChains is the driver instance you use to control the browser, ie browser in this case. Try the following:
menu = browser.find_element_by_xpath("//nav/ul/li/a[#href='#'][.='Profile']")
hover = ActionChains(browser).move_to_element(menu)
hover.perform()