selenium webdriver module has no FirefoxProfile() attribute - python-3.x

Ok, I am trying to set my browsers proxy file, I have everything configured correctly but not entirely sure why I keep getting this error.
Here is my code
from selenium import webdriver
import time
profile = webdriver.FirefoxProfile()
profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.http', "173.255.117.227")
profile.set_preference('network.proxy.http_port', 7779)
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile)
driver.get('whatismyipaddress.com')
time.sleep(4)
driver.close()
This is the error I am getting -
========== RESTART: C:/Users/The Family/Desktop/FireFoxProxyBot.py ==========
Traceback (most recent call last):
File "C:/Users/The Family/Desktop/FireFoxProxyBot.py", line 4, in <module>
profile = webdriver.FirefoxProfile()
AttributeError: 'module' object has no attribute 'FirefoxProfile'
>>>

Related

AttributeError: 'Options' object has no attribute 'set_headless'

I am tried to use a headless google chrome to scrapy some website content in macOS Big Sur, this is my python 3 code:
from webbrowser import Chrome
from dolphin.common.commonlogger import CommonLogger
from selenium.webdriver import chrome
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
class FetchMusic:
def __init__(self):
print("fetch...")
if __name__ == '__main__':
opts = Options()
opts.set_headless()
assert opts.headless # Operating in headless mode
browser = Chrome(executable_path=r"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
options=opts)
browser.implicitly_wait(3)
browser.get('https://ca.finance.yahoo.com/quote/AMZN/profile?p=AMZN')
results = browser.find_elements_by_xpath('//*[#id="quote-header-info"]/div[3]/div/div/span[1]')
for result in results:
print(result.text)
when I run this code, shows error:
Traceback (most recent call last):
File "/Users/dolphin/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/212.5457.59/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py", line 1483, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Users/dolphin/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/212.5457.59/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/dolphin/source/reddwarf/backend/pydolphin/dolphin/biz/music/fetch.py", line 18, in <module>
opts.set_headless()
AttributeError: 'Options' object has no attribute 'set_headless'
python-BaseException
Process finished with exit code 1
what should I do to make it work?
Instead of
opts = Options()
opts.set_headless()
please use
options = ChromeOptions()
options.add_argument("--headless")
or
options = Options()
options.add_argument("--headless")
Imports :
from selenium.webdriver.chrome.options import Options as ChromeOptions

Python Appium - ResourceWarning: Enable tracemalloc to get the object allocation traceback

I tried to run an Appium test case (python) via Pycharm to automated test case on Wearable device. Source code below:
import time
from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
class Untitled(unittest.TestCase):
reportDirectory = 'reports'
reportFormat = 'xml'
dc = {}
testName = 'Untitled'
driver = None
def setUp(self):
self.dc['reportDirectory'] = self.reportDirectory
self.dc['reportFormat'] = self.reportFormat
self.dc['testName'] = self.testName
self.dc['appPackage'] = 'com.fossil.phone'
self.dc['udid'] = 'C3E9244E0238'
self.dc['platformName'] = 'android'
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', self.dc)
def testUntitled(self):
self.driver.press_keycode(3) # home
self.driver.press_keycode(3) # home
self.driver.find_element_by_xpath("xpath=//*[#id='icon' and ./parent::*[(./preceding-sibling::* | ./following-sibling::*)[./*[./*[#text='Phone']]]]]").click()
self.driver.find_element_by_xpath("xpath=//*[#text='Contacts']").click()
self.driver.find_element_by_xpath("xpath=//*[#text='Testing Contact']").click()
self.driver.press_keycode(3) # home
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
unittest.main()
And this is the error message :
Launching unittests with arguments python -m unittest Untitled.Untitled in /Users/nhchung/PycharmProjects/MetQua
Error
Traceback (most recent call last):
File "/usr/local/Cellar/python#3.8/3.8.3_2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/unittest/case.py", line 60, in testPartExecutor
yield
self.error_handler.check_response(response)
File "/usr/local/lib/python3.8/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: pkg, and activity or intent action, are required to start an application
Assertion failed
/usr/local/Cellar/python#3.8/3.8.3_2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/unittest/case.py:704: ResourceWarning: unclosed <socket.socket fd=5, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 64654), raddr=('127.0.0.1', 4723)>
outcome.errors.clear()
ResourceWarning: Enable tracemalloc to get the object allocation traceback
Ran 1 test in 11.614s
FAILED (errors=1)
Process finished with exit code 1
Try many ways but I can not resolve this one.
What should I do now?
I also start appium server before running test case.

ModuleNotFoundError: No module named in PyCharm

I was able to run the project using the command line, but from last 1 day I am not able to run the command from the command line However using GUI the project is running fine...
C:\Users\tester\PycharmProjects\Selenium\SampleProjects\POMProjectDemo\Tests>py
thon login.py
Traceback (most recent call last):
File "login.py", line 6, in <module>
from SampleProjects.POMProjectDemo.Pages.loginPage import LoginPage
ModuleNotFoundError: No module named 'SampleProjects'
C:\Users\tester\PycharmProjects\Selenium\SampleProjects\POMProjectDemo\Tests>py
thon -m unittest login.py
E
======================================================================
ERROR: login (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: login
Traceback (most recent call last):
File "C:\Users\tester\AppData\Local\Programs\Python\Python37-32\lib\unittest\
loader.py", line 154, in loadTestsFromName
module = __import__(module_name)
File "C:\Users\tester\PycharmProjects\Selenium\SampleProjects\POMProjectDemo\
Tests\login.py", line 6, in <module>
from SampleProjects.POMProjectDemo.Pages.loginPage import LoginPage
ModuleNotFoundError: No module named 'SampleProjects'
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (errors=1)
[![Tests/login.py
import time
from selenium import webdriver
import unittest
from selenium.common.exceptions import NoSuchElementException
from SampleProjects.POMProjectDemo.Pages.loginPage import LoginPage
from SampleProjects.POMProjectDemo.Pages.homePage import HomePage
import HtmlTestRunner
from SampleProjects.POMProjectDemo.Utility.XLUtil import getData
class LoginTest(unittest.TestCase):
#classmethod
def setUpClass(cls):
cls.driver = webdriver.Chrome(executable_path='F:/Selenium/chromedriver.exe')
cls.driver.implicitly_wait(10)
cls.driver.maximize_window()
def test_login_valid(self):
path = 'c:/Users/mahmood/PycharmProjects/Selenium_automaton/Login.xlsx'
# global path
driver = self.driver
row = getData.getRowCount(path,'Sheet1')
for r in range(2,row+1):
driver.get("https://opensource-demo.orangehrmlive.com/")
userN = getData.readData(path,'Sheet1',r,1)
passW = getData.readData(path,'Sheet1',r,2)
Same code was running fine, what changes I have done not able to debug it.

Why the error occured python3 with selenium

I learning python recent, but I have some error.
environment python3 , chrome , webdriver(chrome)
from selenium import webdriver
import time
import random
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
driver = webdriver.Chrome("./chromedriver.exe")
mobile_emulation = { "deviceName": 'Nexus 5' }
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
driver = webdriver.Remote(command_executor='https:xxx.com',desired_capabilities = chrome_options.to_capabilities())
driver.get("https:/xxx.com")
num = random.randint(11111111 , 99999999)
red = driver.find_element_by_class_name("***")
red.click()
numBox = driver.find_element_by_name("***")
numBox.send_keys(int(num))
reader = driver.find_element_by_id("***")
reader.send_keys("***")
comment = driver.find_element_by_css_selector(" ***")
comment.click()
and result error is here
Traceback (most recent call last):
File "C:\python\pad\pad.py", line 16, in <module>
driver = webdriver.Remote(command_executor='https:xxx.com',desired_capabilities = chrome_options.to_capabilities())
File "C:\Users\***\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 156, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\***\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 254, in start_session
self.session_id = response['sessionId']
TypeError: string indices must be integers
I think the error because number of this code includes Decimal. but I cant find such number .
please give me advise
This error message...
Traceback (most recent call last):
File "C:\python\pad\pad.py", line 16, in <module>
driver = webdriver.Remote(command_executor='https:xxx.com',desired_capabilities = chrome_options.to_capabilities())
.
TypeError: string indices must be integers
...implies that there was a TypeError while invoking webdriver.Remote() method.
As per your code trials as you are using webdriver.Remote() with the argument command_executor perhaps you were trying to execute your tests in Selenium Grid Configuration.
As per the documentation documentation:
command_executor : remote_connection.RemoteConnection object used to execute commands.
Example:
command_executor='http://127.0.0.1:4444/wd/hub'
The complete implementation:
driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities = chrome_options.to_capabilities())
Note: Here we have considered that the Selenium Grid Hub and Selenium Grid Node are configured, up and running successfully with default configuration on the localhost.
Solution (Python 3.6)
Your effective code block will be:
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("start-maximized")
chrome_options.add_argument('disable-infobars')
#driver = webdriver.Remote(command_executor='https:xxx.com', desired_capabilities = chrome_options.to_capabilities())
driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities = chrome_options.to_capabilities())
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
driver.quit()

Why am i recieving this attribute error when using the requests module?

I am trying to run this code:
import requests
import json
page = requests.get('https://www.wikipedia.org/')
But i continue to recieve this error:
AttributeError: module 'cgi' has no attribute 'FieldStorage'
This code works on one of my computers, but not the other.
Any ideas? Also, i'm not even using the cgi module, so I don't know where this is coming from.
Below is the full traceback:
Traceback (most recent call last):
File "C:/Users/Larson/AppData/Local/Programs/Python/Python36-
32/tetshjwbrifvheruiher.py", line 2, in <module>
import requests
File "C:\Users\Larson\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\requests\__init__.py", line 97, in <module>
from . import utils
File "C:\Users\Larson\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\requests\utils.py", line 11, in <module>
import cgi
File "C:/Users/Larson/AppData/Local/Programs/Python/Python36-32\cgi.py", line
2, in <module>
form = cgi.FieldStorage()
AttributeError: module 'cgi' has no attribute 'FieldStorage'

Resources