when i use real device, this code works successfully
but use android virtual device, this code doesn't work with errors
i tried PC reboot and made a new android virtual device
but not work too
anybody help me T.T
PS. android virtual device successfully work, but app immediately exit after start
this is my code:
import unittest
import os
from appium import webdriver
from time import sleep
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
class TableSearchTest(unittest.TestCase):
def setUp(self):
app = os.path.join(os.path.dirname(__file__), 'E:\\PycharmProjects\\pythonProject\\workspace\\Test_Calculator', 'ApiDemos-debug.apk')
app = os.path.abspath(app)
self.driver = webdriver.Remote(
command_executor='http://127.0.0.1:4723/wd/hub',
desired_capabilities = {
'appium:app': app,
'appium:platformName': 'Android',
'appium:platformVersion': '11',
'appium:deviceName': 'Pixel_3a_XL_API_30',
# 'appium:deviceName': 'R3CN208XN9R',
'appium:automationName': 'Appium',
'appium:appPackage': 'io.appium.android.apis',
'appium:appActivity': 'io.appium.android.apis.ApiDemos',
})
def test_search_field(self):
driver = self.driver
wait = WebDriverWait(driver, 20)
sleep(30)
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TableSearchTest)
unittest.TextTestRunner(verbosity=2).run(suite)
this is error message:
C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\unittest\case.py:618: ResourceWarning: unclosed <socket.socket fd=560, family=2, type=1, proto=0, laddr=('127.0.0.1', 54143), raddr=('127.0.0.1', 4723)>
with outcome.testPartExecutor(self):
ResourceWarning: Enable tracemalloc to get the object allocation traceback
Error
Traceback (most recent call last):
File "E:\PycharmProjects\pythonProject\workspace\Test_Calculator\main.py", line 27, in setUp
self.driver = webdriver.Remote(
^^^^^^^^^^^^^^^^^
File "E:\PycharmProjects\pythonProject\workspace\Test_Calculator\venv\Lib\site-packages\appium\webdriver\webdriver.py", line 267, in __init__
super().__init__(
File "E:\PycharmProjects\pythonProject\workspace\Test_Calculator\venv\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "E:\PycharmProjects\pythonProject\workspace\Test_Calculator\venv\Lib\site-packages\appium\webdriver\webdriver.py", line 357, in start_session
response = self.execute(RemoteCommand.NEW_SESSION, parameters)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\PycharmProjects\pythonProject\workspace\Test_Calculator\venv\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "E:\PycharmProjects\pythonProject\workspace\Test_Calculator\venv\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: socket hang up
Ran 1 test in 10.088s
FAILED (errors=1)
Related
I tried to make a bot which looks up if the Bob Marley TShirt from Ajax Amsterdamn is available.
https://www.adidas.ch/de/ajax-3-jsy/GT9559.html <- there is the link
I was able to get it running (also added an telegram bot to report the succses:
#!/usr/bin/python3
from selenium import webdriver
import requests
token="" # expunged for obvious reasons
chat="" # expunged for obvious reasons
message="Available"
fireFoxOptions = webdriver.FirefoxOptions()
fireFoxOptions.set_headless()
browser = webdriver.Firefox(firefox_options=fireFoxOptions)
browser.get("https://www.adidas.ch/de/ajax-3-jsy/GT9559.html")
if ("Dieses Produkt ist leider ausverkauft." not in browser.page_source):
send_text = 'https://api.telegram.org/bot' + token + '/sendMessage?chat_id=' + chat + '&parse_mode=Markdown&text=' + message
response = requests.get(send_text)
print(response.json())
browser.close()
Working on:
selenium 3.141.0
python 3
Firefox 91.0.2
geckodriver 0.29.1
OS: Manjaro Linux
So after that I tried to deploy it on my Debian 10 Server but here is where the struggle began. I had to install Firefox 78.14.0esr and according to the github release page of the Geckodriver version 0.27.0 of it. Selenium stayed the same with 3.141.0. From what I know and what I researched the versions should be alright but when executed throw this nervewrecking error:
Traceback (most recent call last):
File "./ajax.py", line 18, in <module>
browser = webdriver.Firefox(options=options) #, capabilities=cap, executable_path="/usr/local/bin/geckodriver")
File "/home/webadmin/.local/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
keep_alive=True)
File "/home/webadmin/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/webadmin/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/webadmin/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/webadmin/.local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities
I searched the error up and apparently you have to define the binary paths and the capability "marionette" now I did this and now the code looks like this (including some debugging stuff):
#!/usr/bin/python3
from selenium import webdriver
import requests
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
#token="1995953311:AAH-D7S-MISkCa0yQxUc84Gf978fz0vtoqY"
#chat="1917512203"
message="just a test"
options = FirefoxOptions()
options.add_argument("--headless")
cap = DesiredCapabilities().FIREFOX
cap["marionette"] = False
binary = "/usr/bin/firefox"
options.binary = binary
browser = webdriver.Firefox(options=options, capabilities=cap, executable_path="/usr/local/bin/geckodriver")
browser.get("https://www.adidas.ch/de/ajax-3-jsy/GT9559.html")
if ("Dieses Produkt ist leider ausverkauft." not in browser.page_source):
send_text = 'https://api.telegram.org/bot' + token + '/sendMessage?chat_id=' + chat + '&parse_mode=Markdown&text=' + message
response = requests.get(send_text)
print(response.json())
else:
print("succ")
browser.close()
But now I get the following error:
Traceback (most recent call last):
File "./ajax.py", line 18, in <module>
browser = webdriver.Firefox(options=options, capabilities=cap, executable_path="/usr/local/bin/geckodriver")
File "/home/webadmin/.local/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 191, in __init__
self.binary, timeout)
File "/home/webadmin/.local/lib/python3.7/site-packages/selenium/webdriver/firefox/extension_connection.py", line 52, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "/home/webadmin/.local/lib/python3.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 73, in launch_browser
self._wait_until_connectable(timeout=timeout)
File "/home/webadmin/.local/lib/python3.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 104, in _wait_until_connectable
"The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
Also changing the cap["marionette"] = False to True just gives me the older error message.
Thank You!
I just reverted all the changes, made an Docker container and put that on the server.
I am using EdgeDriver with Selenium and Python 3
I have been able to fix it by manually creating the js folder, but the EdgeDriver window does not load the page, it is showing Data;, in the address bar. These may be related on unrelated errors.
But the scoped_dir13788_764300980 changes when restarting the cmd prompt.
The abridged code is below:
# importing required package of webdriver
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from time import sleep
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.opera.options import Options
from selenium.webdriver.support.wait import WebDriverWait
import schedule
import time
from random import randint
def job():
while True:
# Instantiate the webdriver with the executable location of MS Edge
browser = webdriver.Edge(r"C:\Users\*****\Desktop\msedgedriver.exe")
sleep(2)
browser.maximize_window()
sleep(2)
browser.get('https://********/) #masked the name of website on purpose
try:
# Get the text box to insert Email using selector ID
myElem_1 = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.ID, 'anti-myhub')))
sleep(3)
# Entering the email address
myElem_1.click()
The full error is (ip and user names masked):
[20444:17192:0308/100926.524:ERROR:storage_reserve.cc(164)] Failed to open file to mark as storage reserve: C:\Users\*****\AppData\Local\Temp\scoped_dir13788_764300980\Default\Code Cache\js
DevTools listening on ws://127.0.0.1:59454/devtools/browser/416f15a9-5a69-4025-9322-003aa9672acc
Traceback (most recent call last):
File "check.py", line 79, in <module>
job()
File "check.py", line 21, in job
browser = webdriver.Edge(r"C:\Users\******\Desktop\msedgedriver.exe")
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\edge\webdriver.py", line 66, in __init__
desired_capabilities=capabilities)
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
from tab crashed
(Session info: MicrosoftEdge=**.**.**.**)
I tried to put in the msedge exe in the rool folder and gave the path as "executable_path = '.\msedgedriver.exe'".
I'm trying to test my code using selenium with chrome driver. But I always got this error message in my terminal.
======================================================================
ERROR: test_input_status (myweb.tests.StorySixFunctionalTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/fredypasaud/Documents/PPW/story_six/myweb/tests.py", line 58, in setUp
self.selenium = webdriver.Chrome('./chromedriver',chrome_options = chrome_options)
File "/home/fredypasaud/Documents/PPW/django01/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/home/fredypasaud/Documents/PPW/django01/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/fredypasaud/Documents/PPW/django01/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/fredypasaud/Documents/PPW/django01/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/fredypasaud/Documents/PPW/django01/lib/python3.6/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: Chrome failed to start: exited normally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /snap/bin/chromium is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
And i put my chromedriver in the same directory as the manage.py of my project. And here's some code about from my test.py
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
class StorySixFunctionalTest(TestCase):
def setUp(self):
chrome_options = Options()
self.selenium = webdriver.Chrome('./chromedriver',chrome_options = chrome_options)
chrome_options.add_argument('--dns-prefetch-disable')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('disable-gpu')
chrome_options.addArguments("--disable-extensions");
chrome_options.addArguments("--disable-dev-shm-usage");
super(StorySixFunctionalTest, self).setUp()
def tearDown(self):
self.selenium.quit()
super(StorySixFunctionalTest, self).tearDown()
def test_input_status(self):
selenium = self.selenium
selenium.get('http://127.0.0.1:8000/index/')
status = selenium.find_element_by_id('id_status')
submit = selenium.find_element_by_id('submit')
status.send_keys("Coba Coba")
submit.send_keys(Keys.RETURN)
Update :
I'm trying to debug my program by showing the log of chromedriver, and i got this error instead (which is weird because i have canbera module installed)
Gtk-Message: 14:40:58.177: Failed to load module "canberra-gtk-module"
Gtk-Message: 14:40:58.196: Failed to load module "canberra-gtk-module"
I am trying to get console logs of safari using selenium webdriver.
from selenium import webdriver
import time
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
d = DesiredCapabilities.SAFARI
d['logginfPrefs']={'browser':'ALL'}
driver = webdriver.Safari(desired_capabilities=d)
driver.get("test.com")
time.sleep(10)
driver.find_element_by_xpath("//input[#placeholder='Your Name (Required)']").send_keys("test")
for entry in driver.get_log('browser'):
print entry
time.sleep(10)
But getting following error
Traceback (most recent call last):
File "/Users/Fuzebox_6/PycharmProjects/Codechef/test.py", line 14, in <module>
for entry in driver.get_log('browser'):
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 1053, in get_log
return self.execute(Command.GET_LOG, {'type': log_type})['value']
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in execute
self.error_handler.check_response(response)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 165, in check_response
raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: The command 'POST /session/3A5DB2BA-CE01-4D7C-895E-32F1C3381F7A/log' is not implemented.
Can some one please tell me what are the flags needed to get console logs
I am starting to learn how to become a better test driven developer when creating web applications in Django. I am trying to use Selenium to open a browser, but I am getting an error.
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: /var/folders/xn/bvyw0fm97j1_flsyggj0xn9r0000gp/T/tmptoxt890d If you specified a log_file in the FirefoxBinary constructor, check it for details.
I read that by "Installing the FF extension "Disable Add-on Compatibility Checks" skips this and everything is fine." selenium.common.exceptions.WebDriverException: Message: Can't load the profile. I did this, but It is still not working. I used Python2.7 and Python3.5 with Selenium version 2.53.6.
Python file
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import unittest
caps = DesiredCapabilities.FIREFOX
caps["marionette"] = True
class NewVisitorTest(unittest.TestCase):
def setUp(self):
self.browser = webdriver.Firefox(capabilities=caps)
def tearDown(self):
self.browser.quit()
def test_can_start_a_list_and_retrieve_it_later(self):
self.browser.get('http://localhost:8000')
self.assertIn('To-Do', self.browser.title)
if __name__ == '__main__':
unittest.main(warnings='ignore')
Stack Trace
Creating test database for alias 'default'...
EException ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x103f652b0>>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 151, in __del__
self.stop()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 123, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
======================================================================
ERROR: test_can_start_a_list_and_retrieve_it_later (functional_tests.NewVisitorTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/timothybaney/Treehouse/TDD/superlists/functional_tests.py", line 13, in setUp
self.browser = webdriver.Firefox(capabilities=caps)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 82, in __init__
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 62, in start
stdout=self.log_file, stderr=self.log_file)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
NotADirectoryError: [Errno 20] Not a directory
----------------------------------------------------------------------
Ran 1 test in 0.012s
FAILED (errors=1)
Destroying test database for alias 'default'...
That error is because you are using FF 48. For FF>=47 FirefoxDriver stop working. You must use the new MarionetteDriver
Set up this:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.FIREFOX
caps["marionette"] = True
browser = webdriver.Firefox(capabilities=caps)
browser.get('http://localhost:8000')
assert 'Django' in browser.title