Selenium: NoSuchFrameException for Chrome Extension - python-3.x

I have a Chrome extension and I'd like to test it with Selenium. The extension places an iframe tag to pages.
I can successfully get the iframe tag by running the following command:
top_frame = driver.find_element(By.XPATH, value='//iframe[#class="top-frame"]')
However, when I try switching to the frame I get 'NoSuchFrameException' error.
driver.switch_to.frame(top_frame)
The following line outputs the frame's class name correctly
print(top_frame.get_attribute('class'))
Error log:
Testing http://www.google.com
Traceback (most recent call last):
File "test/run_tests.py", line 200, in <module>
main()
File "test/run_tests.py", line 197, in main
run_tests(args.plugin, args.out, args.url)
File "test/run_tests.py", line 167, in run_tests
button = check_button(driver, url)
File "test/run_tests.py", line 84, in check_button
driver.switch_to.frame(top_frame)
File "/home/burak/.virtualenv/extension/lib/python3.5/site-packages/selenium/webdriver/remote/switch_to.py", line 87, in frame
self._driver.execute(Command.SWITCH_TO_FRAME, {'id': frame_reference})
File "/home/burak/.virtualenv/extension/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/home/burak/.virtualenv/extension/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchFrameException: Message: no such frame: element is not a frame
(Session info: chrome=60.0.3112.90)
(Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Linux 4.10.0-30-generic x86_64)

Try this man,
driver.switch_to.frame(driver.find_element(By.XPATH,value=".//iframe[#src='give your frame source name here..']"));

In the latest version of Chrome, most likely there is a bug that breaks the switch_to_frame() call. Therefore, I started using Firefox instead, everything is smooth for now.

This link is to the associated issue report on Chromium. It has not been resolved yet. (25/10/17)
https://bugs.chromium.org/p/chromedriver/issues/detail?id=2019

Related

getting "selenium.common.exceptions.SessionNotCreatedExceptionSelenium" error using InstaPy

[SETUP:
Windows 10 x64
PyCharm 2019.3.3 (Community Edition)]
I'm trying to create a simple Insta bot with InstaPy but I keep running into the same error
CODE:
from instapy import InstaPy
InstaPy(username='username', password='password').login()
I keep getting the following error:
Traceback (most recent call last):
File "C:/Users/Niku/PycharmProjects/InstaBot/InstaBot.py", line 6, in <module>
InstaPy(username='Rubixmusicprod', password='Niku2020').login()
File "C:\Users\Niku\PycharmProjects\InstaBot\venv\lib\site-packages\instapy\instapy.py", line 309, in __init__
self.browser, err_msg = set_selenium_local_session(
File "C:\Users\Niku\PycharmProjects\InstaBot\venv\lib\site-packages\instapy\browser.py", line 111, in set_selenium_local_session
browser = webdriver.Firefox(
File "C:\Users\Niku\PycharmProjects\InstaBot\venv\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 170, in __init__
RemoteWebDriver.__init__(
File "C:\Users\Niku\PycharmProjects\InstaBot\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\Niku\PycharmProjects\InstaBot\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\Niku\PycharmProjects\InstaBot\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Niku\PycharmProjects\InstaBot\venv\lib\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've tried upgrading selenium, along with Geckodriver and related drivers.
It was a mission just to get InstaPy installed!
I may just have to go the browser automation way instead here.
Any help would be greatly appreciated!!
You must use Selenium with Geckodrive in Firefox
session = InstaPy(username=INSTAGRAM_LOGIN,
password=INSTAGRAM_PASSWORD,
geckodriver_path='geckodriver.exe')

Executing script with Selenium inside <iframe> doesn't work, but when doing in Console it does

I'm automating a service with Selenium, and the website I need to access uses iframes tags, and I need to alter the value of some elements inside this tag.
I was using the Edge WebDriver, but I changed to Chrome because I thought it'd solve the problem, and unfortunately, it didn't, so I don't think it had anything to do with the Driver, but I'd rather keep with Chrome, if possible.
This is the line that simulates the script:
gc.execute_script("""document.evaluate('//*[#id="QRYSELECT_WRK_QRYSEARCHTEXT254"]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.setAttribute('value','foo')""")
And it raises me an exception about null pointers, but basically, it's saying that the browser couldn't find this element, and, therefore, couldn't change its value.
Ironically, when I open the console and write the following command (which is the same script above):
document.evaluate('//*[#id="QRYSELECT_WRK_QRYSEARCHTEXT254"]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.setAttribute('value','foo')
It works.
Here's the traceback to the error when I call execute_script from gc:
Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module>
gc.execute_script("""document.evaluate('//*[#id="QRYSELECT_WRK_QRYSEARCHTEXT254"]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.setAttribute('value','CEL_ADMITIDOS')""")
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\support\event_firing_webdriver.py", line 88, in execute_script
return self._dispatch("execute_script", (script, self._driver), "execute_script", unwrapped_args)
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\support\event_firing_webdriver.py", line 160, in _dispatch
raise e
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\support\event_firing_webdriver.py", line 157, in _dispatch
result = getattr(self._driver, d_call)(*d_args)
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 636, in execute_script
'args': converted_args})['value']
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Program Files\Python36\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 read property 'setAttribute' of null
(Session info: chrome=71.0.3578.98)
(Driver info: chromedriver=71.0.3578.137 (86ee722808adfe9e3c92e6e8ea746ade08423c7e),platform=Windows NT 10.0.17134 x86_64)
So I guess it's probably something related to permissions...? But I don't know, it's quite weird to get two different results to the same script, isn't it?
Thanks!

selenium.common.exceptions.WebDriverException: Message: unknown error: call function result missing 'value'

I am trying to automate my hybrid app, where I need to enter details in an input field but using send_keys("Text value") is not working in my case. I am getting the exception
selenium.common.exceptions.WebDriverException: Message: unknown error: call function result missing 'value'
def test_login(self):
self.driver.implicitly_wait(15)
loginemail = self.driver.find_element_by_id("userId")
loginpass = self.driver.find_element_by_id("userPassword")
email = loginemail.find_element_by_xpath("//*[#id='userId']/input")
email.click()
email.send_keys("xxxxlabs.com")
Here is the full error message:
File "/home/martial/PycharmProjects/pytestAndroid/test_login_android.py", line 45, in test_login
email.send_keys("xxxxlabs.com")
File "/home/martial/PycharmProjects/pytestAndroid/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 347, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': keys_to_typing(value)})
File "/home/martial/PycharmProjects/pytestAndroid/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 491, in _execute
return self._parent.execute(command, params)
File "/home/martial/PycharmProjects/pytestAndroid/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 238, in execute
self.error_handler.check_response(response)
File "/home/martial/PycharmProjects/pytestAndroid/venv/lib/python3.6/site-packages/appium/webdriver/errorhandler.py", line 29, in check_response
raise wde
File "/home/martial/PycharmProjects/pytestAndroid/venv/lib/python3.6/site-packages/appium/webdriver/errorhandler.py", line 24, in check_response
super(MobileErrorHandler, self).check_response(response)
File "/home/martial/PycharmProjects/pytestAndroid/venv/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 193, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: call function result missing 'value'
I was getting this error when using chromedriver v2.33 - when I updated to v2.36 the error went away (this was on the mac using the chromedriver_mac64.zip file downloaded from: https://sites.google.com/a/chromium.org/chromedriver/downloads)
Question: org.openqa.selenium.webdriverexception: unknown error: call function result missing 'value'. Please look into below steps to resolve such error.
Answer: Update browser version. Please follow below steps to get the latest version of browsers.
Go to: https://www.seleniumhq.org/download/
CTRL+F and search "Third Party Browser Drivers". All browsers are listed there.
Click on browser name/version -It redirects to the another page. (E.g.- http://chromedriver.storage.googleapis.com/index.html?path=2.36/)
Download appropriate driver for your operating system.
Place driver into one of folder from where you are calling that driver to your selenium webdriver scripts. It works without any error.
Thanks :) !!

Xvfb Selenium headless Chrome on Linux in Python

I'm trying to run chrome headless with selenium in Python.
I tried xvfb-run -a python3 message.py
And i get this error:
Traceback (most recent call last):
File "message.py", line 388, in <module>
initialize()
File "message.py", line 54, in initialize
driver = webdriver.Chrome(chrome_options = chrome_options)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.33.506178 (69ae10f91723897591ef1a3b465aa5d35011eb5e),platform=Linux 3.13.0-96-generic x86)
And initialize():
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--verbose")
chrome_options.add_argument("--log-path=chrome.log")
chrome_options.add_argument("window-size=1200x600")
chrome_options.add_argument("user-data-dir=\\")
driver = webdriver.Chrome(chrome_options = chrome_options)
driver.get('http://google.com')
I'm using Python 3.5 and chromedriver 2.33.506178 for Linux32 (Ubuntu as Server without Desktop)
I tested the same code on my other pc with linux mint, all works fine.
Hope you can help me :)
After checking my actual rights of writing/reading/executing I found my mistake. chromedriver weren't able to load while trying to execute with root rights.
After I changed chromedrivers permission all works fine now.

Python selenium webdriver "Session not created" exception when opening Chrome

Here's my code for opening Chrome:
from selenium import webdriver
driver=webdriver.Chrome('C:\\Users\\Imran\\AppData\\Local\\Programs\\Python\\Python36\\selenium\\chromedriver.exe')
Error when running program:
Traceback (most recent call last):
File "C:/Users/Imran/PycharmProjects/webscraping/WF Item.py", line 6, in <module>
driver = webdriver.Chrome('C:\\Users\\Imran\\AppData\\Local\\Programs\\Python\\Python36\\selenium\\chromedriver.exe')
File "C:\Users\Imran\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "C:\Users\Imran\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Users\Imran\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "C:\Users\Imran\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Users\Imran\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: session not created exception
from unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"27028.1","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=54.0.2840.71)
(Driver info: chromedriver=2.23.409699 (49b0fa931cda1caad0ae15b7d1b68004acd05129),platform=Windows NT 6.3.9600 x86_64)
Getting the following exception:
selenium.common.exceptions.WebDriverException: Message: session not created exception
Update your chromedriver to 2.24 version from the given url:
http://chromedriver.storage.googleapis.com/index.html?path=2.24/
That worked for me.
Setting LANG=en_US.UTF-8 before executing my script works for me.
See this: https://bugs.chromium.org/p/chromedriver/issues/detail?id=1552#c43
In Python:
import os
os.environ["LANG"] = "en_US.UTF-8"
To install the chromedriver on windows, download and unzip the chromedriver_win32.zip and add the path to the folder containing the chromedriver.exe in the environment variables setting [System properties - Advanced system settings - Environment variables].

Resources