python - Selenium - iframe headache - unable to solve -
i have been banging head against wall long enough okay turn here @ point.
i have page iframe:
<iframe frameborder="0" allowtransparency="true" tabindex="0" src="" title="rich text editor, listing_description" aria-describedby="cke_18" style="width:100%;height:100%">
when xpath using: '//*[@aria-describedby="cke_18"]'
i web element where:
>>> elem <selenium.webdriver.remote.webelement.webelement object @ 0x104327b50> >>> elem.id u'{3dfc8264-71bc-c948-882a-acd6a8b93ab5}' >>> elem.is_displayed <bound method webelement.is_displayed of <selenium.webdriver.remote.webelement.webelement object @ 0x104327b50>>
now, when try extract put information in iframe, along following error:
traceback (most recent call last): file "<stdin>", line 1, in <module> file "/applications/spyder.app/contents/resources/lib/python2.7/spyderlib/widgets/externalshell/sitecustomize.py", line 560, in debugfile debugger.run("runfile(%r, args=%r, wdir=%r)" % (filename, args, wdir)) file "/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/bdb.py", line 400, in run exec cmd in globals, locals file "<string>", line 1, in <module> file "/applications/spyder.app/contents/resources/lib/python2.7/spyderlib/widgets/externalshell/sitecustomize.py", line 540, in runfile execfile(filename, namespace) file "/users/jasonmellone/documents/pythonprojects/nakedapts.py", line 88, in <module> = elem.find_element_by_xpath(".//*") file "/library/python/2.7/site-packages/selenium-2.41.0-py2.7.egg/selenium/webdriver/remote/webelement.py", line 201, in find_element_by_xpath return self.find_element(by=by.xpath, value=xpath) file "/library/python/2.7/site-packages/selenium-2.41.0-py2.7.egg/selenium/webdriver/remote/webelement.py", line 377, in find_element {"using": by, "value": value})['value'] file "/library/python/2.7/site-packages/selenium-2.41.0-py2.7.egg/selenium/webdriver/remote/webelement.py", line 370, in _execute return self._parent.execute(command, params) file "/library/python/2.7/site-packages/selenium-2.41.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 166, in execute self.error_handler.check_response(response) file "/library/python/2.7/site-packages/selenium-2.41.0-py2.7.egg/selenium/webdriver/remote/errorhandler.py", line 164, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.nosuchelementexception: message: u'unable locate element: {"method":"xpath","selector":".//*"}' ; stacktrace: @ firefoxdriver.prototype.findelementinternal_ (file:///var/folders/8x/0msd5dd13l9453ff9739rj7w0000gn/t/tmpmh4are/extensions/fxdriver@googlecode.com/components/driver_component.js:8905) @ firefoxdriver.prototype.findchildelement (file:///var/folders/8x/0msd5dd13l9453ff9739rj7w0000gn/t/tmpmh4are/extensions/fxdriver@googlecode.com/components/driver_component.js:8917) @ delayedcommand.prototype.executeinternal_/h (file:///var/folders/8x/0msd5dd13l9453ff9739rj7w0000gn/t/tmpmh4are/extensions/fxdriver@googlecode.com/components/command_processor.js:10884) @ delayedcommand.prototype.executeinternal_ (file:///var/folders/8x/0msd5dd13l9453ff9739rj7w0000gn/t/tmpmh4are/extensions/fxdriver@googlecode.com/components/command_processor.js:10889) @ delayedcommand.prototype.execute/< (file:///var/folders/8x/0msd5dd13l9453ff9739rj7w0000gn/t/tmpmh4are/extensions/fxdriver@googlecode.com/components/command_processor.js:10831)
now, i, not being selenium developer, have no idea means.
when run following code:
elem = helper.getelementbyxpath(mydriver,'//*[@aria-describedby="cke_18"]',"abc"); mydriver.switch_to_frame(elem);
the above runs helper.getelementbyxpath
is:
def getelementbyxpath(mydriver,xpath,valuestring): try: = mydriver.find_element_by_xpath(xpath); a.send_keys(valuestring); return a; except: print "unexpected error:", sys.exc_info()[0]; return 0; = elem.find_element_by_xpath(".//*")
giving me following:
>>> elem.id u'{8be4819b-f828-534a-9eb2-5b791f42b99a}'
and following statement:
= elem.find_element_by_xpath(".//*")
gives me huge error.
the frustrating part me following:
- i don't need information out of embedded input in iframe, want sendkeys.
- i happy "keys.tab" until reach proper box, , cursor.location.element.send_keys (pseudo code).
- i want type text on page cursor in right place (can't easily?)
my goal send keys here, not deeper, , cannot seem solve problem without getting above issue.
is there way solve this? quite defeated , hope has answer.
thank you!
selenium can access elements in current frame. can switch deeper frame this:
driver.switch_to_frame(identifier)
where identifier is: - name of frame - webelement reference frame - numeric index of frame
api reference here: http://selenium-python.readthedocs.org/en/latest/api.html
when finish in iframe
, can switch top level following:
driver.switch_to_default_content()
Comments
Post a Comment