AttributeError: can't set attribute in appium-python - python

import time
import unittest
from appium.webdriver.webdriver import WebDriver as AppiumDriver
from appium import webdriver
desired_caps = dict(
platformName='Android',
deviceName='Android Emulator',
app=('C:/Users/Asus/Desktop/h.a/asan.apk')
)
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
i recieved this error: appium-python
i got this message:
how can i fix it?
am using appium and android studio emulator to simulate and automation test of android application.
Traceback (most recent call last):
File "C:\Users\Asus\workspace\top web\complete.py", line 19, in <module>
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
File "C:\Users\Asus\AppData\Local\Programs\Python\Python39\lib\site-packages\appium\webdriver\webdriver.py", line 151, in __init__
super().__init__(
File "C:\Users\Asus\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 268, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\Asus\AppData\Local\Programs\Python\Python39\lib\site-packages\appium\webdriver\webdriver.py", line 229, in start_session
self.capabilities = response.get('value')
AttributeError: can't set attribute

I had this same issue and it got fixed by re-installing appium with python instead of npm.
I installed appium from source https://github.com/appium/python-client

Related

Run Selenium directly on Pydroid3 on Android

my goal is to run a python script that uses Selenium to manipulate the chrome browser, directly with Pydroid 3 app on my android smartphone (without a pc connection).
I followed the instructions at the link https://chromedriver.chromium.org/getting-started/getting-started---android to download the appropriate webdriver and set it correctly for Android.
In detail the version of Chrome on my Smartphone (Samsung S10) is 108.0.5359.128 therefore, following what is indicated here:
https://chromedriver.chromium.org/downloads#h.p_ID_32
I downloaded webdriver "chromedriver_linux64.zip" present at the following link:
https://chromedriver.storage.googleapis.com/index.html?path=108.0.5359.71/
But following this example
https://chromedriver.chromium.org/getting-started/getting-started---android#h.p_ID_390 and running the following Python3 script:
from selenium import webdriver
path_to_chromedriver = os.path.dirname(__file__) + '/chromedriver'
print('path_to_chromedriver: ', path_to_chromedriver)
options = webdriver.ChromeOptions()
options.add_experimental_option('androidPackage', 'com.android.chrome')
driver = webdriver.Chrome(path_to_chromedriver, 0, options=options)
driver.get('https://google.com')
driver.quit()
or this one:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
path_to_chromedriver = os.path.dirname(__file__) + '/chromedriver'
print('path_to_chromedriver: ', path_to_chromedriver)
service = Service(path_to_chromedriver)
options = webdriver.ChromeOptions()
options.add_experimental_option('androidPackage', 'com.android.chrome')
driver = webdriver.Chrome(service=service, options=options)
driver.get('https://google.com')
I get this error:
path_to_chromedriver: /storage/emulated/0/Download/ke-ce-verimme-justwatch-scraper/ke-ce-verimme-justwatch-scraper/scrapers/chromedriver
Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module>
start(fakepyfile,mainpyfile)
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
exec(open(mainpyfile).read(), __main__.__dict__)
File "<string>", line 124, in <module>
File "/storage/emulated/0/Download/ke-ce-verimme-justwatch-scraper/ke-ce-verimme-justwatch-scraper/scrapers/justwatchScraper.py", line 168, in start
scrolledGenrePage = scrollGenrePageToTheEnd(genrePageURL)
File "/storage/emulated/0/Download/ke-ce-verimme-justwatch-scraper/ke-ce-verimme-justwatch-scraper/scrapers/justwatchScraper.py", line 47, in scrollGenrePageToTheEnd
driver = webdriver.Chrome(service=service, options=options)
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
super().__init__(
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/selenium/webdriver/chromium/webdriver.py", line 103, in __init__
self.service.start()
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 106, in start
self.assert_process_still_running()
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 117, in assert_process_still_running
return_code = self.process.poll()
AttributeError: 'Service' object has no attribute 'process'
[Program finished]
Can anyone help me or suggest a workaround?

AttributeError: 'Service' object has no attribute 'process' - ChromeDriver Use

receiving the following error when attempting to run Chrome Driver via my Selenium Test in CodeSpace/Workspace.
Traceback (most recent call last):
File "/workspaces/117965322/SeleniumTest", line 5, in <module>
driver = webdriver.Chrome(service=ser)
File "/home/ubuntu/.local/lib/python3.10/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
super().__init__(
File "/home/ubuntu/.local/lib/python3.10/site-packages/selenium/webdriver/chromium/webdriver.py", line 103, in __init__
self.service.start()
File "/home/ubuntu/.local/lib/python3.10/site-packages/selenium/webdriver/common/service.py", line 106, in start
self.assert_process_still_running()
File "/home/ubuntu/.local/lib/python3.10/site-packages/selenium/webdriver/common/service.py", line 117, in assert_process_still_running
return_code = self.process.poll()
AttributeError: 'Service' object has no attribute 'process'
The code I'm running currently is the below:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
ser = Service("/home/ubuntu/.local/lib/python3.10/site-packages/chromedriver")
driver = webdriver.Chrome(service=ser)
driver.get("https://www.google.com")
driver.quit()
I've added the selenium.webdriver.chrome.service line as it removed an issue with the executable path, but not the final Attribute Error?
Any help would be fantastic as have exhausted my Googling capabilities!
Just trying to initially get ChromeDriver working for another project but can't get it to launch due to the above error.

cant get selenium to work i want to test my django channels application

im trying to test my app and even if i do the most basic things my selenium refuses to work all i get is a long error message and i cant figure out why im new to selenium and i cant understand these errors, would love some help, im working on static server in django, would rly love some help.
idk if its important
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels.layers.InMemoryChannelLayer"
}
}
tests.py
import time
from channels.testing import ChannelsLiveServerTestCase
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
class ChatTests(ChannelsLiveServerTestCase):
#classmethod
def setUpClass(cls):
try:
super().setUpClass()
cls.driver = webdriver.Chrome('C:\\Users\\David\\Desktop\\VSProjects\\LiveChat\\chromedriver.exe')
cls.driver.implicitly_wait(10)
except:
cls.tearDownClass()
#classmethod
def tearDownClass(cls):
cls.driver.quit()
super().tearDownClass()
def test_admin_login(self):
self.driver.get(self.live_server_url)
time.sleep(20)
error code
(livechat_env) PS C:\Users\David\Desktop\VSProjects\LiveChat\livechatapp> py manage.py test --keepdb
Found 1 test(s).
Using existing test database for alias 'default'...
System check identified no issues (0 silenced).
DevTools listening on ws://127.0.0.1:53585/devtools/browser/326e028a-0c32-4557-93a4-6c55304bae1d
ETraceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python310\lib\multiprocessing\spawn.py", line 107, in spawn_main
new_handle = reduction.duplicate(pipe_handle,
File "C:\Python310\lib\multiprocessing\reduction.py", line 79, in duplicate
return _winapi.DuplicateHandle(
OSError: [WinError 6] The handle is invalid
======================================================================
ERROR: test_admin_login (room.tests.ChatTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\David\Desktop\VSProjects\LiveChat\livechat_env\lib\site-packages\django\test\testcases.py", line 287, in _setup_and_call
self._pre_setup()
File "C:\Users\David\Desktop\VSProjects\LiveChat\livechat_env\lib\site-packages\channels\testing\live.py", line 52, in _pre_setup
self._server_process.start()
File "C:\Python310\lib\multiprocessing\process.py", line 121, in start
self._popen = self._Popen(self)
File "C:\Python310\lib\multiprocessing\context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "C:\Python310\lib\multiprocessing\context.py", line 327, in _Popen
return Popen(process_obj)
File "C:\Python310\lib\multiprocessing\popen_spawn_win32.py", line 93, in __init__
reduction.dump(process_obj, to_child)
File "C:\Python310\lib\multiprocessing\reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'convert_exception_to_response.<locals>.inner'
----------------------------------------------------------------------
Ran 0 tests in 3.580s
FAILED (errors=1)
Preserving test database for alias 'default'...
I'm not 100% if this works, but I think you can open the url of ur locally hosted website (like "localhost:8000"):
from selenium import webdriver
PATH = "path to your webdriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("localhost:8000")
Hopefully this works

Python Selenium Error: Cannot find Opera binary

i'm trying out Python Selenium with my main browser, Opera, but i get a massive error when i execute the script, here's the python script:
from selenium import webdriver
path = r"C:\Users\sleep\Programs\operadriver_win64\operadriver.exe"
driver = webdriver.Opera(executable_path=path)
driver.get('https://youtube.com')
And here's the error:
Traceback (most recent call last):
File "C:\Users\sleep\Programs\Status-Entrega\main.py", line 6, in <module>
driver = webdriver.Opera(executable_path=r'C:\Users\sleep\Programs\operadriver_win64\operadriver.exe')
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\opera\webdriver.py", line 79, in __init__
OperaDriver.__init__(self, executable_path=executable_path,
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\opera\webdriver.py", line 55, in __init__
ChromiumDriver.__init__(self,
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary
(Driver info: operadriver=91.0.4472.77 (1cecd5c8a856bc2a5adda436e7b84d8d21b339b6-refs/branch-heads/4472#{#1246}),platform=Windows NT 10.0.19042 x86_64)
How can i fix this?
can you try this :
from selenium import webdriver
from selenium.webdriver.opera.options import Options
options = Options()
options.binary_location = r'C:\opera.exe path'
driver = webdriver.Opera(opera_options = options,
executable_path=r'C:\operadriver.exe path')
it might work, don't forget one is the opera path and one is the operadriver path
This link may help: https://github.com/operasoftware/operachromiumdriver/blob/master/examples/desktop.py
import time
from selenium import webdriver
from selenium.webdriver.chrome import service
webdriver_service = service.Service('path/to/operadriver')
webdriver_service.start()
driver = webdriver.Remote(webdriver_service.service_url, webdriver.DesiredCapabilities.OPERA)
driver.get('https://www.google.com/')
input_txt = driver.find_element_by_name('q')
input_txt.send_keys('operadriver\n')
time.sleep(5) #see the result
driver.quit()

Error while Running a WebDriver using Python script

I had a problem running executing a Webdriver using a script in python using the library selenium. I have posted the sample code scenarios as well as the corresponding error thrown while executing.
Code Scenario:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
Error Scenario:
Traceback (most recent call last):
File "C:/Users/Kaushik/Desktop/IMC DEVELOPER TEST/Sample.py", line 4, in <module>
driver = webdriver.Firefox()
File "C:\Python27\lib\site-packages\selenium-2.37.2-py2.7.egg\selenium\webdriver\firefox\webdriver.py", line 59, in __init__
self.binary, timeout),
File "C:\Python27\lib\site-packages\selenium-2.37.2-py2.7.egg\selenium\webdriver\firefox\extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "C:\Python27\lib\site-packages\selenium-2.37.2-py2.7.egg\selenium\webdriver\firefox\firefox_binary.py", line 60, in launch_browser
self._start_from_profile_path(self.profile.path)
File "C:\Python27\lib\site-packages\selenium-2.37.2-py2.7.egg\selenium\webdriver\firefox\firefox_binary.py", line 83, in _start_from_profile_path
env=self._firefox_env).communicate()
File "C:\Python27\lib\subprocess.py", line 709, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 957, in _execute_child
startupinfo)
WindowsError: [Error 87] The parameter is incorrect
I coudnt understand the Error thrown. I just need to use the selenium library to retrieve a dynamic data from a website using a python script.
There is nothing wrong with your code, it works fine for me.
Do you have firefox installed? if not, you can use a different browser. for example:
driver = webdriver.Ie
or
driver = webdriver.Opera

Categories

Resources