本文整理汇总了Python中robot.libraries.BuiltIn.BuiltIn.execute_javascript方法的典型用法代码示例。如果您正苦于以下问题:Python BuiltIn.execute_javascript方法的具体用法?Python BuiltIn.execute_javascript怎么用?Python BuiltIn.execute_javascript使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类robot.libraries.BuiltIn.BuiltIn
的用法示例。
在下文中一共展示了BuiltIn.execute_javascript方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: input_value_on_next_prompt
# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import execute_javascript [as 别名]
def input_value_on_next_prompt(self, value=None):
"""模拟prompt窗口输入value后点击ok的情况,同时记录窗口中的message。
不输入value参数时,则模拟prompt窗口在默认值情况下被点击ok的情况。
当页面存在window.prompt()时,必须在prompt窗口出现前使用该关键字。
每次有新页面加载之后必须重新调用这个关键字才会生效。
"""
s2l = BuiltIn().get_library_instance('Selenium2Library')
if value is None:
js = """
window.prompt = function(message, defaultValue) {
lastPopupMessage = message;
return defaultValue;
}
"""
s2l.execute_javascript('%s' % js)
else:
js_prefix = """
window.prompt = function(message, defaultValue) {
lastPopupMessage = message;
return '"""
js_suffix = "';}"
s2l.execute_javascript('%s%s%s' % (js_prefix, value, js_suffix))
示例2: prep_alert
# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import execute_javascript [as 别名]
def prep_alert():
"""
Overrides window.alert to simply store the alert message rather than
display it. This will become unnecessary once GhostDriver supports alerts
natively.
"""
seleniumlib = BuiltIn().get_library_instance('Selenium2Library')
js = """
window.alert = function(message) {
lastAlert = message;
}
"""
logger.debug('Overriding window.alert to store the alert message')
seleniumlib.execute_javascript('%s' % js)
示例3: choose_cancel_on_next_prompt
# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import execute_javascript [as 别名]
def choose_cancel_on_next_prompt(self):
"""模拟prompt窗口点击cancel的情况,同时记录窗口中的message。
当页面存在window.prompt()时,必须在prompt窗口出现前使用该关键字。
每次有新页面加载之后必须重新调用这个关键字才会生效。
"""
s2l = BuiltIn().get_library_instance('Selenium2Library')
js = """
window.prompt = function(message, defaultValue) {
lastPopupMessage = message;
return null;
}
"""
s2l.execute_javascript('%s' % js)
示例4: choose_cancel_on_next_confirmation
# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import execute_javascript [as 别名]
def choose_cancel_on_next_confirmation(self):
"""模拟confirmation窗口点击cancel的情况,同时记录窗口中的message。
当页面存在window.confirm()时,必须在confirmation窗口出现前使用该关键字。
每次有新页面加载之后必须重新调用这个关键字才会生效。
"""
s2l = BuiltIn().get_library_instance('Selenium2Library')
js = """
window.confirm = function(message) {
lastPopupMessage = message;
return false;
}
"""
s2l.execute_javascript('%s' % js)
示例5: close_on_next_alert
# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import execute_javascript [as 别名]
def close_on_next_alert(self):
"""模拟alert窗口被关闭的情况,同时记录窗口中的message。
当页面存在window.alert()时,必须在alert窗口出现前使用该关键字。
每次有新页面加载之后必须重新调用这个关键字才会生效。
"""
s2l = BuiltIn().get_library_instance('Selenium2Library')
js = """
window.alert = function(message) {
lastPopupMessage = message;
return;
}
"""
s2l.execute_javascript('%s' % js)
示例6: close_popup
# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import execute_javascript [as 别名]
def close_popup():
"""
Closes a popup window that was opened with "Open Popup"
"""
seleniumlib = BuiltIn().get_library_instance('Selenium2Library')
if not hasattr(seleniumlib, 'main_window'):
raise UsageError('Popups must be opened with the same Selenium2Library'
' instance before they can be closed')
#This overrides any modal creation (e.g. "are you sure?")
seleniumlib.execute_javascript('window.onbeforeunload = function() {}')
browser = seleniumlib._current_browser()
logger.debug('Closing window: %s' % browser.current_window_handle)
seleniumlib.close_window()
logger.debug('Switching to window: %s' % seleniumlib.main_window)
browser.switch_to_window(seleniumlib.main_window)
示例7: get_element_text
# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import execute_javascript [as 别名]
def get_element_text(self, element, child):
"""Returns the text found at the 'child' of the 'element' """
selenium = BuiltIn().get_library_instance("Selenium2Library")
id = selenium.get_element_attribute(element + "@id")
print "id:" + str(id)
return selenium.execute_javascript(
'return document.getElementById("' + id + '").childNodes[' + str(child) + "].textContent"
)
示例8: get_items_in_context_menu
# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import execute_javascript [as 别名]
def get_items_in_context_menu(self, locator):
"""Returns the text from the context menu located by 'locator' """
selenium = BuiltIn().get_library_instance("Selenium2Library")
return selenium.execute_javascript(
"return document.getElementById('dashMenu_4').getElementsByTagName'div')[1].getElementsByClassName('rich-menu-item rich-menu-item-enabled')["
+ str(locator)
+ "].getElementsByTagName('span')[1].textContent"
)
示例9: get_last_popup_message
# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import execute_javascript [as 别名]
def get_last_popup_message(self):
"""获取最后一次弹出框(alert/confirmation/prompt)中显示的文字。
当页面存在window.alert()或者window.confirm()时,在alert/confirmation/prompt窗口出现后使用该关键字。
只有在alert/confirmation/prompt窗口出现之前调用过这个库的`Close On Next Alert`,
`Choose Ok On Next Confirmation`, `Choose Cancel On Next Confirmation`,
`Input Value On Next Prompt`, `Choose Cancel On Next Prompt`这些关键字之后,这个关键字才能起作用。
"""
s2l = BuiltIn().get_library_instance('Selenium2Library')
js = """
return lastPopupMessage;
"""
return s2l.execute_javascript('%s' % js)
示例10: _BrowserManagementKeywords
# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import execute_javascript [as 别名]
#.........这里部分代码省略.........
#OperatingSystem().set_environment_variable("ONDEMAND_PYRO", "1111")
#os.environ['ONDEMAND_PYRO'] = ondemand_string
self._seleniumlib.maximize_browser_window()
# Determine timeouts based on commandline
# IMPLICIT_WAIT
# COMMAND_DELAY
# KEYWORD_TIMEOUT
if 'IMPLICIT_WAIT' in os.environ:
self._seleniumlib.set_selenium_implicit_wait(os.environ.get('IMPLICIT_WAIT'))
if 'COMMAND_DELAY' in os.environ:
self._seleniumlib.set_selenium_speed(os.environ.get('COMMAND_DELAY'))
else:
print '(open_pyro_browser) setting selenium speed %s' % selenium_speed
self._seleniumlib.set_selenium_speed(selenium_speed)
if 'KEYWORD_TIMEOUT' in os.environ:
self._seleniumlib.set_selenium_timeout(os.environ.get('KEYWORD_TIMEOUT'))
def sencha_login(self, user_name, password, element_on_next_page, suspend_timeouts=True):
#def sencha_login(self, user_name, password, element_on_next_page):
"""
Using the instantiated browser from `Open Browser`, the page traverses through the login page and waits for the targeted element on the following page.
"""
print '(login_sencha)'
self._seleniumlib.wait_until_element_is_visible('loginnameid-inputEl', timeout=5)
self._seleniumlib.wait_until_element_is_visible('loginpasswordid-inputEl', timeout=5)
self._seleniumlib.input_text('loginnameid-inputEl', user_name)
self._seleniumlib.input_text('loginpasswordid-inputEl', password)
self._seleniumlib.wait_until_element_is_visible('loginbuttonid-btnIconEl', timeout=5)
self._seleniumlib.click_element('id=loginbuttonid-btnIconEl')
self._seleniumlib.wait_until_element_is_visible('id=%s'% element_on_next_page, timeout=5)
if suspend_timeouts == True:
print '(login_sencha) javascript issuing suspendAll!'
self._seleniumlib.execute_javascript('window.ADTRAN.store.RefreshBaseStore.suspendAll();')
self._seleniumlib.execute_javascript('window.ADTRAN.util.SysPollTask.suspend();')
def close_pyro_browser():
print '(close_pyro_browser)'
# sauce enabled
#self._seleniumlib = BuiltIn().get_library_instance('Selenium2Library')
if self._remoteBrowser:
assert USERNAME_ACCESS_KEY.match(os.environ["PYROBOT_REMOTE_URL"]), 'Incomplete remote_url.'
username, access_key = USERNAME_ACCESS_KEY.findall(os.environ["PYROBOT_REMOTE_URL"])[0][1:]
suite_name = BuiltIn().get_variable_value("${SUITE_NAME}")
suite_status = BuiltIn().get_variable_value("${SUITE STATUS}")
tags = BuiltIn().get_variable_value("${TEST_TAGS}")
print "name: %s status: %s tags: %s" % (suite_name, suite_status, tags)
token = (':'.join([username, access_key])).encode('base64').strip()
payload = { 'name': suite_name,
'passed': suite_status == 'PASS',
'tags': tags}
headers = {'Authorization': 'Basic {0}'.format(token)}
url = 'https://saucelabs.com/rest/v1/{0}/jobs/{1}'.format(username, self._job_id)
response = requests.put(url, data=json.dumps(payload), headers=headers)
assert response.status_code == 200, response.text
# video_url = json.loads(response.text).get('video_url')
# if video_url:
# logger.info('<a href="{0}">video.flv</a>'.format(video_url), html=True)
ondemand_string = "SauceOnDemandSessionID=%s job-name=%s" % (self._job_id, suite_name)
print 'setting ONDEMAND_PYRO to : %s' % ondemand_string
os.environ['ONDEMAND_PYRO'] = ondemand_string
#wrapper = Wrapper(self._seleniumlib, username, access_key, sys.argv[2])
#wrapper.update_sauce_rest(BuiltIn().get_variable_value("${SUITE STATUS}"), BuiltIn().get_variable_value("${TEST_TAGS}"))
示例11: get_last_alert
# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import execute_javascript [as 别名]
def get_last_alert():
"""
Gets the last alert message. This command MUST be preceeded by Prep Alert
"""
seleniumlib = BuiltIn().get_library_instance('Selenium2Library')
return seleniumlib.execute_javascript('return lastAlert')