Selenium Documentation 中文翻译

来源:互联网 发布:软件项目管理知识体系 编辑:程序博客网 时间:2024/05/17 11:35

Selenium 用户手册

Translator:ChipDate:2011-08-01

INDEX

  • 1   __init__(self, host, port, browserStartCommand, browserURL)
  • 2   setExtensionJs(self, extensionJs)
  • 3   start(self)
  • 4   stop(self)
  • 5   do_command(self, verb, args)
  • 6   get_string(self, verb, args)
  • 7   get_string_array(self, verb, args)
  • 8   get_number(self, verb, args)
  • 9   get_number_array(self, verb, args)
  • 10   get_boolean(self, verb, args)
  • 11   get_boolean_array(self, verb, args)
  • 12   click(self, locator)
  • 13   double_click(self, locator)
  • 14   context_menu(self, locator)
  • 15   click_at(self, locator, coordString)
  • 16   double_click_at(self, locator, coordString)
  • 17   context_menu_at(self, locator, coordString)
  • 18   fire_event(self, locator, eventName)
  • 19   focus(self, locator)
  • 20   key_press(self, locator, keySequence)
  • 21   shift_key_down(self)
  • 22   shift_key_up(self)
  • 23   meta_key_down(self)
  • 24   meta_key_up(self)
  • 25   alt_key_down(self)
  • 26   alt_key_up(self)
  • 27   control_key_down(self)
  • 28   control_key_up(self)
  • 29   key_down(self, locator, keySequence)
  • 30   key_up(self, locator, keySequence)
  • 31   mouse_over(self, locator)
  • 32   mouse_out(self, locator)
  • 33   mouse_down(self, locator)
  • 34   mouse_down_right(self, locator)
  • 35   mouse_down_at(self, locator, coordString)
  • 36   mouse_down_right_at(self, locator, coordString)
  • 37   mouse_up(self, locator)
  • 38   mouse_up_right(self, locator)
  • 39   mouse_up_at(self, locator, coordString)
  • 40   mouse_up_right_at(self, locator, coordString)
  • 41   mouse_move(self, locator)
  • 42   mouse_move_at(self, locator, coordString)
  • 43   type(self, locator, value)
  • 44   type_keys(self, locator, value)
  • 45   set_speed(self, value)
  • 46   get_speed(self)
  • 47   check(self, locator)
  • 48   uncheck(self, locator)
  • 49   select(self, selectLocator, optionLocator)
  • 50   add_selection(self, locator, optionLocator)
  • 51   remove_selection(self, locator, optionLocator)
  • 52   remove_all_selections(self, locator)
  • 53   submit(self, formLocator)
  • 54   open(self, url)
  • 55   open_window(self, url, windowID)
  • 56   select_window(self, windowID)
  • 57   select_pop_up(self, windowID)
  • 58   deselect_pop_up(self)
  • 59   select_frame(self, locator)
  • 60   get_whether_this_frame_match_frame_expression(self, currentFrameString, target)
  • 61   get_whether_this_window_match_window_expression(self, currentWindowString, target)
  • 62   wait_for_pop_up(self, windowID, timeout)
  • 63   choose_cancel_on_next_confirmation(self)
  • 64   choose_ok_on_next_confirmation(self)
  • 65   answer_on_next_prompt(self, answer)
  • 66   go_back(self)
  • 67   refresh(self)
  • 68   close(self)
  • 69   is_alert_present(self)
  • 70   is_prompt_present(self)
  • 71   is_confirmation_present(self)
  • 72   get_alert(self)
  • 73   get_confirmation(self)
  • 74   get_prompt(self)
  • 75   get_location(self)
  • 76   get_title(self)
  • 77   get_body_text(self)
  • 78   get_value(self, locator)
  • 79   get_text(self, locator)
  • 80   highlight(self, locator)
  • 81   get_eval(self, script)
  • 82   is_checked(self, locator)
  • 83   get_table(self, tableCellAddress)
  • 84   get_selected_labels(self, selectLocator)
  • 85   get_selected_label(self, selectLocator)
  • 86   get_selected_values(self, selectLocator)
  • 87   get_selected_value(self, selectLocator)
  • 88   get_selected_indexes(self, selectLocator)
  • 89   get_selected_index(self, selectLocator)
  • 90   get_selected_ids(self, selectLocator)
  • 91   get_selected_id(self, selectLocator)
  • 92   is_something_selected(self, selectLocator)
  • 93   get_select_options(self, selectLocator)
  • 94   get_attribute(self, attributeLocator)
  • 95   is_text_present(self, pattern)
  • 96   is_element_present(self, locator)
  • 97   is_visible(self, locator)
  • 98   is_editable(self, locator)
  • 99   get_all_buttons(self)
  • 100   get_all_links(self)
  • 101   get_all_fields(self)
  • 102   get_attribute_from_all_windows(self, attributeName)
  • 103   dragdrop(self, locator, movementsString)
  • 104   set_mouse_speed(self, pixels)
  • 105   get_mouse_speed(self)
  • 106   drag_and_drop(self, locator, movementsString)
  • 107   drag_and_drop_to_object(self, locatorOfObjectToBeDragged,locatorOfDragDestinationObject)
  • 108   window_focus(self)
  • 109   window_maximize(self)
  • 110   get_all_window_ids(self)
  • 111   get_all_window_names(self)
  • 112   get_all_window_titles(self)
  • 113   get_html_source(self)
  • 114   set_cursor_position(self, locator, position)
  • 115   get_element_index(self, locator)
  • 116   is_ordered(self, locator1, locator2)
  • 117   get_element_position_left(self, locator)
  • 118   get_element_position_top(self, locator)
  • 119   get_element_width(self, locator)
  • 120   get_element_height(self, locator)
  • 121   get_cursor_position(self, locator)
  • 122   get_expression(self, expression)
  • 123   get_xpath_count(self, xpath)
  • 124   assign_id(self, locator, identifier)
  • 125   allow_native_xpath(self, allow)
  • 126   ignore_attributes_without_value(self, ignore)
  • 127   wait_for_condition(self, script, timeout)
  • 128   set_timeout(self, timeout)
  • 129   wait_for_page_to_load(self, timeout)
  • 130   wait_for_frame_to_load(self, frameAddress, timeout)
  • 131   get_cookie(self)
  • 132   get_cookie_by_name(self, name)
  • 133   is_cookie_present(self, name)
  • 134   create_cookie(self, nameValuePair, optionsString)
  • 135   delete_cookie(self, name, optionsString)
  • 136   delete_all_visible_cookies(self)
  • 137   set_browser_log_level(self, logLevel)
  • 138   run_script(self, script)
  • 139   add_location_strategy(self, strategyName, functionDefinition)
  • 140   capture_entire_page_screenshot(self, filename, kwargs)
  • 141   rollup(self, rollupName, kwargs)
  • 142   add_script(self, scriptContent, scriptTagId)
  • 143   remove_script(self, scriptTagId)
  • 144   use_xpath_library(self, libraryName)
  • 145   set_context(self, context)
  • 146   attach_file(self, fieldLocator, fileLocator)
  • 147   capture_screenshot(self, filename)
  • 148   capture_screenshot_to_string(self)
  • 149   captureNetworkTraffic(self, type)
  • 150   addCustomRequestHeader(self, key, value)
  • 151   capture_entire_page_screenshot_to_string(self, kwargs)
  • 152   shut_down_selenium_server(self)
  • 153   retrieve_last_remote_control_logs(self)
  • 154   key_down_native(self, keycode)
  • 155   key_up_native(self, keycode)
  • 156   key_press_native(self, keycode)

1   __init__(self, host, port, browserStartCommand, browserURL)

2   setExtensionJs(self, extensionJs)

3   start(self)

4   stop(self)

5   do_command(self, verb, args)

6   get_string(self, verb, args)

7   get_string_array(self, verb, args)

8   get_number(self, verb, args)

9   get_number_array(self, verb, args)

10   get_boolean(self, verb, args)

11   get_boolean_array(self, verb, args)

12   click(self, locator)

Clicks on a link, button, checkbox or radio button. If the click action causes a new page to load (like a link usually does), call waitForPageToLoad. 'locator' is an element locator

-点击一个连接、按钮、勾选框或者单选按钮。如果点击事件会造成新页面的加载,则会调用waitForPageToLoad。‘locator’是指元素定位器

13   double_click(self, locator)

Double clicks on a link, button, checkbox or radio button. If the double click action causes a new page to load (like a link usually does), call waitForPageToLoad. 'locator' is an element locator

双击一个连接、按钮、勾选框或者单元按钮。如果双击事件会造成新页面的加载,则会调用waitForPageToLoad。‘locator’是指元素定位器

14   context_menu(self, locator)

Simulates opening the context menu for the specified element (as might happen if the user "right-clicked" on the element). 'locator' is an element locator

模拟在一个元素上打开右键菜单

15   click_at(self, locator, coordString)

Clicks on a link, button, checkbox or radio button. If the click action causes a new page to load (like a link usually does), call waitForPageToLoad. 'locator' is an element locator 'coordString' is specifies the x,y position (i.e. 10,20) of the mouse event relative to the element returned by the locator.

点击一个连接、按钮、勾选框或者单选按钮。如果点击事件会造成新页面的加载,则会调用waitForPageToLoad。‘coordString’是由定位器返回的元素鼠标事件的相对x,y坐标

16   double_click_at(self, locator, coordString)

Doubleclicks on a link, button, checkbox or radio button. If the action causes a new page to load (like a link usually does), call waitForPageToLoad. 'locator' is an element locator 'coordString' is specifies the x,y position (i.e. 10,20) of the mouse event relative to the element returned by the locator.

同上,只是双击。

17   context_menu_at(self, locator, coordString)

Simulates opening the context menu for the specified element (as might happen if the user "right-clicked" on the element). 'locator' is an element locator 'coordString' is specifies the x,y position (i.e. 10,20) of the mouse event relative to the element returned by the locator.

同context_menu,只是限定了与定位器的相对坐标。

18   fire_event(self, locator, eventName)

Explicitly simulate an event, to trigger the corresponding "onevent" handler. 'locator' is an element locator 'eventName' is the event name, e.g. "focus" or "blur"

显示的模拟事件发生,调用事件响应“onevent” handler。

19   focus(self, locator)

Move the focus to the specified element; for example, if the element is an input field, move the cursor to that field. 'locator' is an element locator

转移焦点到指定的元素。比如:使光标到指定的输入框。

20   key_press(self, locator, keySequence)

Simulates a user pressing and releasing a key. 'locator' is an element locator 'keySequence' is Either be a string("" followed by the numeric keycode of the key to be pressed, normally the ASCII value of that key), or a single character. For example: "w", " 9".

模拟用户压下与释放按键。 'keySequence' 可以是一个字符串(要按下的键的ASCII值,比如"\13"),也可以是单独的字母,比如"w"

21   shift_key_down(self)

Press the shift key and hold it down until doShiftUp() is called or a new page is loaded.

模拟按下shift键,并且保持按下,直到调用 doShiftUp(),或者一个新的页面被加载。

22   shift_key_up(self)

Release the shift key.

释放shift键。

23   meta_key_down(self)

Press the meta key and hold it down until doMetaUp() is called or a new page is loaded.

模拟按下复合键,并且保持按下,直到调用doMetaUp(),或者一个新的页面被加载。

24   meta_key_up(self)

Release the meta key.

释放复合键

25   alt_key_down(self)

Press the alt key and hold it down until doAltUp() is called or a new page is loaded.

按下alt键,直到doAltUp()被调用或者新的页面被加载。

26   alt_key_up(self)

Release the alt key.

释放alt键

27   control_key_down(self)

Press the control key and hold it down until doControlUp() is called or a new page is loaded.

按下control键直到doControlUp()被调用,或者新的页面被加载。

28   control_key_up(self)

Release the control key.

释放control键

29   key_down(self, locator, keySequence)

Simulates a user pressing a key (without releasing it yet). 'locator' is an element locator 'keySequence' is Either be a string("" followed by the numeric keycode of the key to be pressed, normally the ASCII value of that key), or a single character. For example: "w", " 9".

模拟用户按下某个键(不释放)。

30   key_up(self, locator, keySequence)

Simulates a user releasing a key. 'locator' is an element locator 'keySequence' is Either be a string("" followed by the numeric keycode of the key to be pressed, normally the ASCII value of that key), or a single character. For example: "w", " 9".

模拟用户释放某个键。

31   mouse_over(self, locator)

Simulates a user hovering a mouse over the specified element. 'locator' is an element locator

模拟用户鼠标徘徊在某个特定元素。

32   mouse_out(self, locator)

Simulates a user moving the mouse pointer away from the specified element. 'locator' is an element locator

模拟用户移动鼠标指针离开某个元素。

33   mouse_down(self, locator)

Simulates a user pressing the left mouse button (without releasing it yet) on the specified element. 'locator' is an element locator

模拟用户在某元素上按下鼠标左键(而不释放)。

34   mouse_down_right(self, locator)

Simulates a user pressing the right mouse button (without releasing it yet) on the specified element. 'locator' is an element locator

模拟用户在某元素上按下鼠标右键(而不释放)。

35   mouse_down_at(self, locator, coordString)

Simulates a user pressing the left mouse button (without releasing it yet) at the specified location. 'locator' is an element locator 'coordString' is specifies the x,y position (i.e. 10,20) of the mouse event relative to the element returned by the locator.

加入了相对坐标的mouse_down。

36   mouse_down_right_at(self, locator, coordString)

Simulates a user pressing the right mouse button (without releasing it yet) at the specified location. 'locator' is an element locator 'coordString' is specifies the x,y position (i.e. 10,20) of the mouse event relative to the element returned by the locator.

加入了相对坐标的mouse_down_right。

37   mouse_up(self, locator)

Simulates the event that occurs when the user releases the mouse button (i.e., stops holding the button down) on the specified element. 'locator' is an element locator

模拟用户在某个元素上释放鼠标。

38   mouse_up_right(self, locator)

Simulates the event that occurs when the user releases the right mouse button (i.e., stops holding the button down) on the specified element. 'locator' is an element locator

模拟用户在某个元素上释放鼠标右键。

39   mouse_up_at(self, locator, coordString)

Simulates the event that occurs when the user releases the mouse button (i.e., stops holding the button down) at the specified location. 'locator' is an element locator 'coordString' is specifies the x,y position (i.e. 10,20) of the mouse event relative to the element returned by the locator.

加入了相对坐标的mouse_up。

40   mouse_up_right_at(self, locator, coordString)

Simulates the event that occurs when the user releases the right mouse button (i.e., stops holding the button down) at the specified location. 'locator' is an element locator 'coordString' is specifies the x,y position (i.e. 10,20) of the mouse event relative to the element returned by the locator.

加了相对坐标的mouse_up_right

41   mouse_move(self, locator)

Simulates a user pressing the mouse button (without releasing it yet) on the specified element. 'locator' is an element locator

模拟用户在特定元素上按下鼠标(不释放)。

42   mouse_move_at(self, locator, coordString)

Simulates a user pressing the mouse button (without releasing it yet) on the specified element. 'locator' is an element locator 'coordString' is specifies the x,y position (i.e. 10,20) of the mouse event relative to the element returned by the locator.

加了相对坐标的mouse_move_at

43   type(self, locator, value)

Sets the value of an input field, as though you typed it in. Can also be used to set the value of combo boxes, check boxes, etc. In these cases, value should be the value of the option selected, not the visible text. 'locator' is an element locator 'value' is the value to type

模拟用户输入一样在输入框中输入内容。 也可以用于设置下拉框、勾选框等的值。在上述情况下,值应该是选项的值,而不是显示的文本。

44   type_keys(self, locator, value)

Simulates keystroke events on the specified element, as though you typed the value key-by-key. This is a convenience method for calling keyDown, keyUp, keyPress for every character in the specified string; this is useful for dynamic UI widgets (like auto-completing combo boxes) that require explicit key events. Unlike the simple "type" command, which forces the specified value into the page directly, this command may or may not have any visible effect, even in cases where typing keys would normally have a visible effect. For example, if you use "typeKeys" on a form element, you may or may not see the results of what you typed in the field. In some cases, you may need to use the simple "type" command to set the value of the field and then the "typeKeys" command to send the keystroke events corresponding to what you just typed. 'locator' is an element locator 'value' is the value to type

模拟用户在元素上连续的敲击按键。 这算是为每个字符调用keyDown, keyUp, keyPress以输出字符串的简便方法。这对于一些需要显示调用按键时间的动态UI控件非常有用。 不同于简单的type命令的是,这个命令执行时可能会有可视化的效果。 在一些情况下,你可能需要使用type命令去设置一个域的值,然后调用typeKeys命令来对你刚键入的值进行敲击时间响应。

45   set_speed(self, value)

Set execution speed (i.e., set the millisecond length of a delay which will follow each selenium operation). By default, there is no such delay, i.e., the delay is 0 milliseconds. 'value' is the number of milliseconds to pause after operation

设置每条语句执行的间隔时间(微秒),默认没有任何延迟。

46   get_speed(self)

Get execution speed (i.e., get the millisecond length of the delay following each selenium operation). By default, there is no such delay, i.e., the delay is 0 milliseconds. See also setSpeed.

获取每条语句执行的间隔时间(微秒)

47   check(self, locator)

Check a toggle-button (checkbox/radio) 'locator' is an element locator

勾选一个开关按钮(勾选框/单选框)

48   uncheck(self, locator)

Uncheck a toggle-button (checkbox/radio) 'locator' is an element locator

去除勾选一个开关按钮

49   select(self, selectLocator, optionLocator)

Select an option from a drop-down using an option locator. Option locators provide different ways of specifying options of an HTML Select element (e.g. for selecting a specific option, or for asserting that the selected option satisfies a specification). There are several forms of Select Option Locator. • label=labelPattern: matches options based on their labels, i.e. the visible text. (This is the default.) ○ label=regexp:^[Oo]ther • value=valuePattern: matches options based on their values. ○ value=other • id=id: matches options based on their ids. ○ id=option1 • index=index: matches an option based on its index (offset from zero). ○ index=2 If no option locator prefix is provided, the default behaviour is to match on label. 'selectLocator' is an element locator identifying a drop-down menu 'optionLocator' is an option locator (a label by default)

选中一个下拉框的选项。 OptionLocators 提供了不同的方法用于定位一个html选择元素的选项。 以下是OptionLocator的几种格式: ○ label=labelPattern: 根据label来匹配选项(默认)。 § label=regexp: ^[Oo]ther ○ value=valuePattern: 根据值来匹配选项 § value=other ○ id=id: 根据IDs来匹配选项 § id=option1 ○ index=index: 根据序号来匹配选项(从0起) § index=2 如果没有提供选项定位器,默认的行为是匹配label。

50   add_selection(self, locator, optionLocator)

Add a selection to the set of selected options in a multi-select element using an option locator. @see #doSelect for details of option locators 'locator' is an element locator identifying a multi-select box 'optionLocator' is an option locator (a label by default)

为多选元素添加被选中的选项。

51   remove_selection(self, locator, optionLocator)

Remove a selection from the set of selected options in a multi-select element using an option locator. @see #doSelect for details of option locators 'locator' is an element locator identifying a multi-select box 'optionLocator' is an option locator (a label by default)

去除多选元素中的选项。

52   remove_all_selections(self, locator)

Unselects all of the selected options in a multi-select element. 'locator' is an element locator identifying a multi-select box

移除所有的多选元素的选项。

53   submit(self, formLocator)

Submit the specified form. This is particularly useful for forms without submit buttons, e.g. single-input "Search" forms. 'formLocator' is an element locator for the form you want to submit

提交表单。这对于没有提交按钮的表单尤其有用,比如:单一输入的“搜索”表单。

54   open(self, url)

Opens an URL in the test frame. This accepts both relative and absolute URLs. The "open" command waits for the page to load before proceeding, ie. the "AndWait" suffix is implicit. Note: The URL must be on the same domain as the runner HTML due to security restrictions in the browser (Same Origin Policy). If you need to open an URL on another domain, use the Selenium Server to start a new browser session on that domain. 'url' is the URL to open; may be relative or absolute

在测试框架中打开一个URL(绝对 or 相对) open命令会等待页面加载后才进入下一步处理,相当于隐式的调用了"AndWait"。 提示:作为参数的URL必须与runner HTML具有相同的域名(由于浏览器的“同源策略”的安全限制)。如果你想要打开另一个域名的URL,可以利用selenium server来启动一个新的浏览器会话。

55   open_window(self, url, windowID)

Opens a popup window (if a window with that ID isn't already open). After opening the window, you'll need to select it using the selectWindow command. This command can also be a useful workaround for bug SEL-339. In some cases, Selenium will be unable to intercept a call to window.open (if the call occurs during or before the "onLoad" event, for example). In those cases, you can force Selenium to notice the open window's name by using the Selenium openWindow command, using an empty (blank) url, like this: openWindow("", "myFunnyWindow"). 'url' is the URL to open, which can be blank 'windowID' is the JavaScript window ID of the window to select

打开一个弹出窗口(如果相同ID的窗口不存在)。打开窗口后,可以通过调用selectWindow命令来选中它。 该命令同样可以用于避开bug SEL-339。在某些情况下,selenium无法拦截window.open指令(比如,该调用发生在onLoad时间发生时或者发生前)。在那些情况下,你可以强迫selenium使用openWindow命令来选中已打开的窗口,使用空白的url,比如openWindow("", "myFunnyWindow")。

56   select_window(self, windowID)

Selects a popup window using a window locator; once a popup window has been selected, all commands go to that window. To select the main window again, use null as the target. Window locators provide different ways of specifying the window object: by title, by internal JavaScript "name," or by JavaScript variable. • title=My Special Window: Finds the window using the text that appears in the title bar. Be careful; two windows can share the same title. If that happens, this locator will just pick one. • name=myWindow: Finds the window using its internal JavaScript "name" property. This is the second parameter "windowName" passed to the JavaScript method window.open(url, windowName, windowFeatures, replaceFlag) (which Selenium intercepts). • var=variableName: Some pop-up windows are unnamed (anonymous), but are associated with a JavaScript variable name in the current application window, e.g. "window.foo = window.open(url);". In those cases, you can open the window using "var=foo". If no window locator prefix is provided, we'll try to guess what you mean like this: 1.) if windowID is null, (or the string "null") then it is assumed the user is referring to the original window instantiated by the browser). 2.) if the value of the "windowID" parameter is a JavaScript variable name in the current application window, then it is assumed that this variable contains the return value from a call to the JavaScript window.open() method. 3.) Otherwise, selenium looks in a hash it maintains that maps string names to window "names". 4.) If that fails, we'll try looping over all of the known windows to try to find the appropriate "title". Since "title" is not necessarily unique, this may have unexpected behavior. If you're having trouble figuring out the name of a window that you want to manipulate, look at the Selenium log messages which identify the names of windows created via window.open (and therefore intercepted by Selenium). You will see messages like the following for each window as it is opened: debug: window.open call intercepted; window ID (which you can use with selectWindow()) is "myNewWindow" In some cases, Selenium will be unable to intercept a call to window.open (if the call occurs during or before the "onLoad" event, for example). (This is bug SEL-339.) In those cases, you can force Selenium to notice the open window's name by using the Selenium openWindow command, using an empty (blank) url, like this: openWindow("", "myFunnyWindow"). 'windowID' is the JavaScript window ID of the window to select

根据window定位器选中一个弹出窗口;一旦弹出窗口被选中,所有的命令都会在此窗口中执行。如果想再次选中主窗口,请使用null作为目标窗口。 可以通过多种方式来确定一个window定位器:标题,内部JavaScript "name",或者JavaScript变量。 ○ title=My Special Window:通过显示在标题栏的文本来定位窗口。如果两个window使用同一个标题,那么定位器会随机挑选一个。 ○ name=myWindow:使用内部JavaScript "name"属性来定位窗口。即JavaScript方法window.open(url, windowName, windowFeatures, replaceFlag)中的第二个传入参数。 ○ var=variableName:有些弹出窗口时匿名的,但可以通过当前应用窗口的JavaScript变量来定位,比如:"window.foo=window.open(url);"。这些情况下,你可以使用"var=foo"来打开窗口。 如果没有提供窗口定位器前缀,我们就会试着去猜: ○ 如果windowID为空(或字符串"null"),那么selenium就会认为用户指的是被浏览器实例化的原始窗口。 ○ 如果windowID参数的值,是当前应用窗口中JavaScript的变量名,selenium就会认为这个变量包含的是调用JavaScript的window.open()方法的返回值。 ○ 否则得话,selenium去它维护的一张字符串名映射window "names"的哈希表中去查找。 ○ 如果以上都失败,selenium就会遍历所有已知的windows,来找寻合适的“标题”。由于“标题”`不是唯一的,所以这会造成不可知的行为。 如果你不知道如何获得你想要控制的窗口的名称,那就去看看selenium的日志信息,这些日志是selenium用于区分由window.open创建的窗口(然后拦截)的名称的。你会看到每个窗口打开是产生的类似如下的信息: debug: window.open call intercepted; window ID (which you can use with selectWindow()) is "myNewWindow" 在某些情况下,selenium无法拦截window.open指令(比如,该调用发生在onLoad时间发生时或者发生前,bug SEL-339)。在那些情况下,你可以强迫selenium使用openWindow命令来选中已打开的窗口,使用空白的url,比如openWindow("", "myFunnyWindow")

57   select_pop_up(self, windowID)

Simplifies the process of selecting a popup window (and does not offer functionality beyond what selectWindow() already provides). • If windowID is either not specified, or specified as "null", the first non-top window is selected. The top window is the one that would be selected by selectWindow() without providing a windowID . This should not be used when more than one popup window is in play. • Otherwise, the window will be looked up considering windowID as the following in order: 1) the "name" of the window, as specified to window.open(); 2) a javascript variable which is a reference to a window; and 3) the title of the window. This is the same ordered lookup performed by selectWindow . 'windowID' is an identifier for the popup window, which can take on a number of different meanings

简化选择一个弹出窗口的过程(不提供比selectWindow()更多的功能) ○ 如果windowID要么没有指定,要么指定为"null",那么第一个非顶层的窗口将被选中。顶层窗口是当selectWindow没有提供任何windowID时被选中的那个窗口。此方法在存在多余一个弹出窗口时不应该被使用。 ○ 否则,windowID就会以以下顺序被查询:1)由window.open()指定的窗口的"name";2)一个指向某个窗口的JavaScript变量;3)窗口的标题。这与selectWindow查询的顺序是一致的。

58   deselect_pop_up(self)

Selects the main window. Functionally equivalent to using selectWindow() and specifying no value for windowID.

选择主窗口。功能上与不指定windowID的值时调用selectWindow()等效。

59   select_frame(self, locator)

Selects a frame within the current window. (You may invoke this command multiple times to select nested frames.) To select the parent frame, use "relative=parent" as a locator; to select the top frame, use "relative=top". You can also select a frame by its 0-based index number; select the first frame with "index=0", or the third frame with "index=2". You may also use a DOM expression to identify the frame you want directly, like this: dom=frames["main"].frames["subframe"] 'locator' is an element locator identifying a frame or iframe

选中一个当前窗口中的frame。(你可以通过多次调用这个方法来选择嵌入的frame)使用"relative=parent"作为locator来选中parent frame。使用"relative=top"来选中top frame。你也可以通过由0开始计数的序列号来选中一个frame。 你也可以通过使用DOM表达式来直接指定将要选中的frame,比如: dom=frames["main"].frames["subframe"]

60   get_whether_this_frame_match_frame_expression(self, currentFrameString, target)

Determine whether current/locator identify the frame containing this running code. This is useful in proxy injection mode, where this code runs in every browser frame and window, and sometimes the selenium server needs to identify the "current" frame. In this case, when the test calls selectFrame, this routine is called for each frame to figure out which one has been selected. The selected frame will return true, while all others will return false. 'currentFrameString' is starting frame 'target' is new frame (which might be relative to the current one)

判断当前(or 定位器)是否识别包含执行代码的frame。 此方法可用于代理注入模式,在这种模式下代码可以在每一个浏览器的frame与窗口中执行,有时selenium server需要定位“当前的”frame。在这种情况下,当测试调用selectFrame时,此程序就会被调用,用来确定哪一个frame是被选中的。被选中的frame会返回true,其余的则会返回false。 'currentFrameString'是启动frame,'target'是新开frame(可能与当前窗口有关联)。

61   get_whether_this_window_match_window_expression(self, currentWindowString, target)

Determine whether currentWindowString plus target identify the window containing this running code. This is useful in proxy injection mode, where this code runs in every browser frame and window, and sometimes the selenium server needs to identify the "current" window. In this case, when the test calls selectWindow, this routine is called for each window to figure out which one has been selected. The selected window will return true, while all others will return false. 'currentWindowString' is starting window 'target' is new window (which might be relative to the current one, e.g., "_parent")

判断 currentWindowString + target 是否识别包含执行代码的窗口。 此方法可用于代理注入模式,在这种模式下代码可以在每一个浏览器的frame与窗口中执行,有时selenium server需要定位“当前的”window。在这种情况下,当测试调用selectWindow时,此程序就会被调用,用来确定哪一个window是被选中的。被选中的window会返回true,其余的则会返回false。 'currentWindowString'是启动窗口,'target'是新开窗口(可能与当前窗口有关联,比如"_parent")。

62   wait_for_pop_up(self, windowID, timeout)

Waits for a popup window to appear and load up. 'windowID' is the JavaScript window "name" of the window that will appear (not the text of the title bar) If unspecified, or specified as "null", this command will wait for the first non-top window to appear (don't rely on this if you are working with multiple popups simultaneously). 'timeout' is a timeout in milliseconds, after which the action will return with an error. If this value is not specified, the default Selenium timeout will be used. See the setTimeout() command.

等待弹出窗口显示并加载。 如果没有指定给的话,'windowID'是将要弹出的窗口的JavaScript窗口的'name'值,或者指定为'null',这个指令将会等待第一个非顶层窗口出现(当多个弹出窗口同时存在是,就不要依赖这个方法了)。

63   choose_cancel_on_next_confirmation(self)

By default, Selenium's overridden window.confirm() function will return true, as if the user had manually clicked OK; after running this command, the next call to confirm() will return false, as if the user had clicked Cancel. Selenium will then resume using the default behavior for future confirmations, automatically returning true (OK) unless/until you explicitly call this command for each confirmation. Take note every time a confirmation comes up, you must consume it with a corresponding getConfirmation, or else the next selenium operation will fail.

默认情况下,selenium被重载的函数window.confirm()会返回true,行为如同用户手动点击了OK;执行此命令后,下一次调用confirm()就会返回false,如同用户点击了cancel。selenium对于接下来的确认恢复使用默认行为,除非你显示地调用此命令来处理每一次确认,否则将会自动地返回true(OK)。 注意:每次确认,你都需要用相应的getConfirmation来干掉它,否则下一个selenium操作就会失败。

64   choose_ok_on_next_confirmation(self)

Undo the effect of calling chooseCancelOnNextConfirmation. Note that Selenium's overridden window.confirm() function will normally automatically return true, as if the user had manually clicked OK, so you shouldn't need to use this command unless for some reason you need to change your mind prior to the next confirmation. After any confirmation, Selenium will resume using the default behavior for future confirmations, automatically returning true (OK) unless/until you explicitly call chooseCancelOnNextConfirmation for each confirmation. Take note every time a confirmation comes up, you must consume it with a corresponding getConfirmation, or else the next selenium operation will fail.

撤销调用chooseCancelOnNextConfirmation的效果。selenium重载的函数window.confirm()正常情况下会自动返回true,行为如同用户手动点击OK,所以除非你需要该表下一次确认的优先级,否则你没有必要调用此指令。在确认过之后,selenium将对接下来的确认执行默认操作,自动返回true(OK),除非(直到)你为每一次确认显示地调用chooseCancelOnNextConfirmation。

65   answer_on_next_prompt(self, answer)

Instructs Selenium to return the specified answer string in response to the next JavaScript prompt [window.prompt()]. 'answer' is the answer to give in response to the prompt pop-up

指示selenium为下一次JavaScript提示[window.prompt()]返回指定的应答字符串。

66   go_back(self)

Simulates the user clicking the "back" button on their browser.

模拟用户点击浏览器的“返回”按钮。

67   refresh(self)

Simulates the user clicking the "Refresh" button on their browser.

模拟用户点击浏览器的“刷新”按钮。

68   close(self)

Simulates the user clicking the "close" button in the titlebar of a popup window or tab.

模拟用户点击弹出框或者页签的“关闭”按钮。

69   is_alert_present(self)

Has an alert occurred? This function never throws an exception

判断是否出现过警告。 这个函数不会抛出任何异常。

70   is_prompt_present(self)

Has a prompt occurred? This function never throws an exception

判断是否出现过提示框。 这个函数不会抛出任何异常。

71   is_confirmation_present(self)

Has confirm() been called? This function never throws an exception

判断confirm()是否被调用过。 这个函数不会抛出任何异常。

72   get_alert(self)

Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts. Getting an alert has the same effect as manually clicking OK. If an alert is generated but you do not consume it with getAlert, the next Selenium action will fail. Under Selenium, JavaScript alerts will NOT pop up a visible alert dialog. Selenium does NOT support JavaScript alerts that are generated in a page's onload() event handler. In this case a visible dialog WILL be generated and Selenium will hang until someone manually clicks OK.

返回上一个动作产生的JavaScript警告信息,如果没有警告则失败。 获得警告与手动点击OK有相同的效果。如果警告框没有被getAlert关掉,下一个Selenium行为就会失败。 使用Selenium时,JavaScript不会弹出可见的警告对话框。 Selenium不支持页面onload事件触发的JavaScript警告。这种情况下,可见的对话框如果弹出,selenium将会挂起,直到有人手动点击OK。

73   get_confirmation(self)

Retrieves the message of a JavaScript confirmation dialog generated during the previous action. By default, the confirm function will return true, having the same effect as manually clicking OK. This can be changed by prior execution of the chooseCancelOnNextConfirmation command. If an confirmation is generated but you do not consume it with getConfirmation, the next Selenium action will fail. NOTE: under Selenium, JavaScript confirmations will NOT pop up a visible dialog. NOTE: Selenium does NOT support JavaScript confirmations that are generated in a page's onload() event handler. In this case a visible dialog WILL be generated and Selenium will hang until you manually click OK.

获得上一个动作产生的JavaScript确认对话框的信息. 默认情况下,确认函数会返回true,如同手动点击OK的效果。这个效果可以被优先级更高的chooseCancelOnNextConfirmation()命令的执行所改变。 如果产生了确认框,但是你又没有手动点击掉它,那写一个selenium操作将会失败。

74   get_prompt(self)

Retrieves the message of a JavaScript question prompt dialog generated during the previous action. Successful handling of the prompt requires prior execution of the answerOnNextPrompt command. If a prompt is generated but you do not get/verify it, the next Selenium action will fail. NOTE: under Selenium, JavaScript prompts will NOT pop up a visible dialog. NOTE: Selenium does NOT support JavaScript prompts that are generated in a page's onload() event handler. In this case a visible dialog WILL be generated and Selenium will hang until someone manually clicks OK.

获得上一个行为产生的JavaScript问题提示对话框信息。对提示对话框的handling是否成功,取决于answerOnNextPrompt命令优先执行的是否成功。如果提示对话框产生但你没有得到(验证)它,下一个selenium行为就会失败。

75   get_location(self)

Gets the absolute URL of the current page.

返回当前页面的绝对URL地址。

76   get_title(self)

Gets the title of the current page.

得到当前页面的标题。

77   get_body_text(self)

Gets the entire text of the page.

得到当前页面的文本。

78   get_value(self, locator)

Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter). For checkbox/radio elements, the value will be "on" or "off" depending on whether the element is checked or not. 'locator' is an element locator

得到具有value属性的指定控件的值。对于checkbox/radio控件,根据该控件选中与否,值为'on' or 'off'。

79   get_text(self, locator)

Gets the text of an element. This works for any element that contains text. This command uses either the textContent (Mozilla-like browsers) or the innerText (IE-like browsers) of the element, which is the rendered text shown to the user. 'locator' is an element locator

得到具有text属性的指定控件的文本信息。

80   highlight(self, locator)

Briefly changes the backgroundColor of the specified element yellow. Useful for debugging. 'locator' is an element locator

简要的将选中的控件的背景色改为黄色。在debug的时候很有用。

81   get_eval(self, script)

Gets the result of evaluating the specified JavaScript snippet. The snippet may have multiple lines, but only the result of the last line will be returned. Note that, by default, the snippet will run in the context of the "selenium" object itself, so this will refer to the Selenium object. Use window to refer to the window of your application, e.g. window.document.getElementById('foo') If you need to use a locator to refer to a single element in your application page, you can usethis.browserbot.findElement("id=foo") where "id=foo" is your locator. 'script' is the JavaScript snippet to run

获得指定JavaScript片段的评估结果。片段可能有多行,但只有最后一行的结果会被返回。 注意:默认情况下,片段会运行在selenium对象自身的上下文中,所以这会参考到selenium对象。使用窗口来指向你应用程序的窗口,e.g. window.document.getElementById('foo')。 如果你需要使用定位器指定你页面内的单个元素,你可以使用 this.browserbot.findElement('id=foo'), 其中'id=foo'就是你的定位器。

82   is_checked(self, locator)

Gets whether a toggle-button (checkbox/radio) is checked. Fails if the specified element doesn't exist or isn't a toggle-button. 'locator' is an element locator pointing to a checkbox or radio button

获得一个开关按钮(checkbox/radio)是否被选中。如果指定的控件,或者开关按钮不存在,则返回失败。 定位器是指向checkbox与单选按钮的控件定位器。

83   get_table(self, tableCellAddress)

Gets the text from a cell of a table. The cellAddress syntax tableLocator.row.column, where row and column start at 0. 'tableCellAddress' is a cell address, e.g. "foo.1.4"

  • 获得表格中一个单元格的文本。单元格地址的语法是:tableLocator.row.column,其中row与column均以0为起始。

84   get_selected_labels(self, selectLocator)

Gets all option labels (visible text) for selected options in the specified select or multi-select element. 'selectLocator' is an element locator identifying a drop-down menu

获得指定的选择(多选)框的被选中内容的标签(可见文本)。

85   get_selected_label(self, selectLocator)

Gets option label (visible text) for selected option in the specified select element. 'selectLocator' is an element locator identifying a drop-down menu

获得选择框中选中内容的标签。

86   get_selected_values(self, selectLocator)

Gets all option values (value attributes) for selected options in the specified select or multi-select element. 'selectLocator' is an element locator identifying a drop-down menu

获得选择框或多选框中被选中内容的值。

87   get_selected_value(self, selectLocator)

Gets option value (value attribute) for selected option in the specified select element. 'selectLocator' is an element locator identifying a drop-down menu

获得选择框中被选中内容的值。

88   get_selected_indexes(self, selectLocator)

Gets all option indexes (option number, starting at 0) for selected options in the specified select or multi-select element. 'selectLocator' is an element locator identifying a drop-down menu

获得选择框(多选框)中指定选项的索引。

89   get_selected_index(self, selectLocator)

Gets option index (option number, starting at 0) for selected option in the specified select element. 'selectLocator' is an element locator identifying a drop-down menu

90   get_selected_ids(self, selectLocator)

Gets all option element IDs for selected options in the specified select or multi-select element. 'selectLocator' is an element locator identifying a drop-down menu

获得下拉菜单中被选中的元素的ID。

91   get_selected_id(self, selectLocator)

Gets option element ID for selected option in the specified select element. 'selectLocator' is an element locator identifying a drop-down menu

92   is_something_selected(self, selectLocator)

Determines whether some option in a drop-down menu is selected. 'selectLocator' is an element locator identifying a drop-down menu

判断是否下拉菜单中有选项被选中。

93   get_select_options(self, selectLocator)

Gets all option labels in the specified select drop-down. 'selectLocator' is an element locator identifying a drop-down menu

获得下拉菜单中所有选项的标签。

94   get_attribute(self, attributeLocator)

Gets the value of an element attribute. The value of the attribute may differ across browsers (this is the case for the "style" attribute, for example). 'attributeLocator' is an element locator followed by an @ sign and then the name of the attribute, e.g. "foo@bar"

获得一个元素属性的值。此属性值可能由于不同浏览器而不同,比如‘style’属性。 'attributeLocator' 是元素定位器,其后跟着@符号和属性的名称。

95   is_text_present(self, pattern)

Verifies that the specified text pattern appears somewhere on the rendered page shown to the user. 'pattern' is a pattern to match with the text of the page

验证给定的文本模式是否存在于呈现给用户的被渲染的页面中。

96   is_element_present(self, locator)

Verifies that the specified element is somewhere on the page. 'locator' is an element locator

验证给定的元素在是否在页面中。

97   is_visible(self, locator)

Determines if the specified element is visible. An element can be rendered invisible by setting the CSS "visibility" property to "hidden", or the "display" property to "none", either for the element itself or one if its ancestors. This method will fail if the element is not present. 'locator' is an element locator

判断给定的元素是否是可见的。元素可以通过在CSS的'visibility'属性中设置'hidden',或者'display'属性设置'none',被设置为不可见,无论是元素资深还是它的祖先。如果此元素不存在则方法返回失败。

98   is_editable(self, locator)

Determines whether the specified input element is editable, ie hasn't been disabled. This method will fail if the specified element isn't an input element. 'locator' is an element locator

判断给定的输入元素是否可以编辑。如果给定元素不是输入元素,则方法失败。

99   get_all_buttons(self)

Returns the IDs of all buttons on the page. If a given button has no ID, it will appear as "" in this array.

返回页面上所有按钮的ID。 如果给定的按钮没有ID,则数组中该ID显示为""。

101   get_all_fields(self)

Returns the IDs of all input fields on the page. If a given field has no ID, it will appear as "" in this array.

返回页面上所有输入域的ID。

102   get_attribute_from_all_windows(self, attributeName)

Returns every instance of some attribute from all known windows. 'attributeName' is name of an attribute on the windows

返回所有已知窗口中某一属性的实例。

103   dragdrop(self, locator, movementsString)

deprecated use dragAndDrop instead 'locator' is an element locator 'movementsString' is offset in pixels from the current location to which the element should be moved, e.g., "+70,-300"

反对使用, 使用 dragAndDrop。

104   set_mouse_speed(self, pixels)

Configure the number of pixels between "mousemove" events during dragAndDrop commands (default=10). Setting this value to 0 means that we'll send a "mousemove" event to every single pixel in between the start location and the end location; that can be very slow, and may cause some browsers to force the JavaScript to timeout. If the mouse speed is greater than the distance between the two dragged objects, we'll just send one "mousemove" at the start location and then one final one at the end location. 'pixels' is the number of pixels between "mousemove" events

设置dragAndDrop命令执行时的鼠标移动的像素步长,默认为10。 设置此值为0,意味着将为起始位置与结束位置间的每一个像素发送一个'mousemove'事件,这样做的话运行会非常的慢,甚至可能造成一些浏览器强制JavaScript超时。 如果鼠标移动步长要比两个拖动点的距离还大,selenium就只会在起始位置与结束为止发送'mousemove'事件。

105   get_mouse_speed(self)

Returns the number of pixels between "mousemove" events during dragAndDrop commands (default=10).

返回dragAndDrop命令执行时的鼠标移动的像素步长,默认为10.

106   drag_and_drop(self, locator, movementsString)

Drags an element a certain distance and then drops it 'locator' is an element locator 'movementsString' is offset in pixels from the current location to which the element should be moved, e.g., "+70,-300"

拖动一个元素一定的距离。 'movementsString'是像素的偏移值,相对与起始位置。e.g. "+70,-300"

107   drag_and_drop_to_object(self, locatorOfObjectToBeDragged,locatorOfDragDestinationObject)

Drags an element and drops it on another element 'locatorOfObjectToBeDragged' is an element to be dragged 'locatorOfDragDestinationObject' is an element whose location (i.e., whose center-most pixel) will be the point where locatorOfObjectToBeDragged is dropped

拖动一个元素到另一个元素。

108   window_focus(self)

Gives focus to the currently selected window

为当前选中的窗口给予焦点。

109   window_maximize(self)

Resize currently selected window to take up the entire screen

使当前选中的窗口全屏。

110   get_all_window_ids(self)

Returns the IDs of all windows that the browser knows about.

返回浏览器所知道的所有窗口的ID。

111   get_all_window_names(self)

Returns the names of all windows that the browser knows about.

返回浏览器所知道的所有窗口的名称。

112   get_all_window_titles(self)

Returns the titles of all windows that the browser knows about.

返回浏览器所知道的所有窗口的标题。

113   get_html_source(self)

Returns the entire HTML source between the opening and closing "html" tags.

返回html开合与闭合标签之间的所有HTML源码。

114   set_cursor_position(self, locator, position)

Moves the text cursor to the specified position in the given input element or textarea. This method will fail if the specified element isn't an input element or textarea. 'locator' is an element locator pointing to an input element or textarea 'position' is the numerical position of the cursor in the field; position should be 0 to move the position to the beginning of the field. You can also set the cursor to -1 to move it to the end of the field.

移动输入元素或文本域中的文本光标至指定的位置。如果指定元素不是输入元素或者文本域,则方法失败。 position是指定过的光标位置。0为开头,-1为结尾。

115   get_element_index(self, locator)

Get the relative index of an element to its parent (starting from 0). The comment node and empty text node will be ignored. 'locator' is an element locator pointing to an element

获得一个元素相对与其父元素的相对位置(从0起始)。注释节点与空文本节点叫会被忽视。

116   is_ordered(self, locator1, locator2)

Check if these two elements have same parent and are ordered siblings in the DOM. Two same elements will not be considered ordered. 'locator1' is an element locator pointing to the first element 'locator2' is an element locator pointing to the second element

查看两个元素是否拥有相同的父元素,且在DOM中有顺序关系。两个相同的元素不会被认为是有序的。

117   get_element_position_left(self, locator)

Retrieves the horizontal position of an element 'locator' is an element locator pointing to an element OR an element itself

获得一个元素的水平坐标。

118   get_element_position_top(self, locator)

Retrieves the vertical position of an element 'locator' is an element locator pointing to an element OR an element itself

获得一个元素的垂直坐标。

119   get_element_width(self, locator)

Retrieves the width of an element 'locator' is an element locator pointing to an element

获得一个元素的宽度。

120   get_element_height(self, locator)

Retrieves the height of an element 'locator' is an element locator pointing to an element

获得一个元素的高度。

121   get_cursor_position(self, locator)

Retrieves the text cursor position in the given input element or textarea; beware, this may not work perfectly on all browsers. Specifically, if the cursor/selection has been cleared by JavaScript, this command will tend to return the position of the last location of the cursor, even though the cursor is now gone from the page. This is filed as SEL-243. This method will fail if the specified element isn't an input element or textarea, or there is no cursor in the element. 'locator' is an element locator pointing to an input element or textarea

获得给定输入元素或文本域的文本光标的位置;提示:本功能不是在所有浏览器都能完美工作。 特殊情况:如果光标(或者选择)被JavaScript清除了,此命令将返回光标最后的位置,即使光标目前不在此页中。 文档在SEL-243中。

122   get_expression(self, expression)

Returns the specified expression. This is useful because of JavaScript preprocessing. It is used to generate commands like assertExpression and waitForExpression. 'expression' is the value to return

返回指定的表达式。 由于JavaScript的预处理,所以此方法很有用。它可以用来生成类似于assertExpression & waitForExpression命令。

123   get_xpath_count(self, xpath)

Returns the number of nodes that match the specified xpath, eg. "//table" would give the number of tables. 'xpath' is the xpath expression to evaluate. do NOT wrap this expression in a 'count()' function; we will do that for you.

返回符合给定xpath的节点的数量,比如"//table"会返回表格的数量。

124   assign_id(self, locator, identifier)

Temporarily sets the "id" attribute of the specified element, so you can locate it in the future using its ID rather than a slow/complicated XPath. This ID will disappear once the page is reloaded. 'locator' is an element locator pointing to an element 'identifier' is a string to be used as the ID of the specified element

临时设置指定元素的'id'属性,以方便在之后的操作中通过ID指定,而不是用又慢又复杂的XPath。此ID在页面被重新载入后消失。

125   allow_native_xpath(self, allow)

Specifies whether Selenium should use the native in-browser implementation of XPath (if any native version is available); if you pass "false" to this function, we will always use our pure-JavaScript xpath library. Using the pure-JS xpath library can improve the consistency of xpath element locators between different browser vendors, but the pure-JS version is much slower than the native implementations. 'allow' is boolean, true means we'll prefer to use native XPath; false means we'll only use JS Xpath

指定selenium是否可以使用本地浏览器内容值得XPath引用(如果本地版本可用);如果你向函数中传递了"false",则你需要selenium的纯JavaScript xpath库。使用纯JS xpath库可以提高不同浏览器间xpath元素定位器的一致性,但是纯JS版本要比本机实现要慢。 'allow'是布尔类型。

126   ignore_attributes_without_value(self, ignore)

Specifies whether Selenium will ignore xpath attributes that have no value, i.e. are the empty string, when using the non-native xpath evaluation engine. You'd want to do this for performance reasons in IE. However, this could break certain xpaths, for example an xpath that looks for an attribute whose value is NOT the empty string. The hope is that such xpaths are relatively rare, but the user should have the option of using them. Note that this only influences xpath evaluation when using the ajaxslt engine (i.e. not "javascript-xpath"). 'ignore' is boolean, true means we'll ignore attributes without value at the expense of xpath "correctness"; false means we'll sacrifice speed for correctness.

指定当使用非本地xpath评估引擎时,selenium是否无视没有值(空字符串)的xpath属性。当你想提高IE中的性能时可以使用此方法。但是,执行此方法有可能会破坏特别的xpath,比如一个查找属性不是空字符串的xpath。 幸运的是此类xpath相对来说很少,但是用户仍然应该有选择的使用它们。 提示:这个只会影响使用ajaxslt引擎时的xpath评估。 'ignore'是布尔变量,true意味着我们会在损坏xpath正确性的情况下忽视没有值得属性;false意味着我们会为了正确性而牺牲速度。

127   wait_for_condition(self, script, timeout)

Runs the specified JavaScript snippet repeatedly until it evaluates to "true". The snippet may have multiple lines, but only the result of the last line will be considered. Note that, by default, the snippet will be run in the runner's test window, not in the window of your application. To get the window of your application, you can use the JavaScript snippet selenium.browserbot.getCurrentWindow(), and then run your JavaScript in there 'script' is the JavaScript snippet to run 'timeout' is a timeout in milliseconds, after which this command will return with an error

重复执行指定的JavaScript片段,直到它评估为'true'。此片段可能包含多行,但只有最后一行的结果会作为参考。 提示:默认情况下,这个片段会在执行者的测试窗口中执行,而不是在你的应用窗口中。为了获得你的应用的窗口,你可以使用JavaScript片段 selenium.browserbot.getCurrentWindow(),然后再你的JavaScript中执行。 timeout的单位是微秒。

128   set_timeout(self, timeout)

Specifies the amount of time that Selenium will wait for actions to complete. Actions that require waiting include "open" and the "waitFor*" actions. The default timeout is 30 seconds. 'timeout' is a timeout in milliseconds, after which the action will return with an error

设置selenium行为的超时时间。默认为30秒。

129   wait_for_page_to_load(self, timeout)

Waits for a new page to load. You can use this command instead of the "AndWait" suffixes, "clickAndWait", "selectAndWait", "typeAndWait" etc. (which are only available in the JS API). Selenium constantly keeps track of new pages loading, and sets a "newPageLoaded" flag when it first notices a page load. Running any other Selenium command after turns the flag to false. Hence, if you want to wait for a page to load, you must wait immediately after a Selenium command that caused a page-load. 'timeout' is a timeout in milliseconds, after which this command will return with an error

等待一个新的页面载入。 你可以使用这个命令来替代'AndWait'作为后缀的命令(这些命令只可以在JS API中使用)。 selenium总是会跟踪新页面的加载,并且当他第一次注意到一个页面的加载时,设置newPageLoaded标志位。当词标志位被置为false后再执行其他的selenium命令。因此,如果你想要等待一个页面的加载,你必须在一个导致新页面加载的selenium命令运行后立即等待。

130   wait_for_frame_to_load(self, frameAddress, timeout)

Waits for a new frame to load. Selenium constantly keeps track of new pages and frames loading, and sets a "newPageLoaded" flag when it first notices a page load. See waitForPageToLoad for more information. 'frameAddress' is FrameAddress from the server side 'timeout' is a timeout in milliseconds, after which this command will return with an error

等待一个新的frame加载。

136   delete_all_visible_cookies(self)

Calls deleteCookie with recurse=true on all cookies visible to the current page. As noted on the documentation for deleteCookie, recurse=true can be much slower than simply deleting the cookies using a known domain/path.

递归地调用deleteCookie删除当前页面的所有课件的cookie,会很慢。

137   set_browser_log_level(self, logLevel)

Sets the threshold for browser-side logging messages; log messages beneath this threshold will be discarded. Valid logLevel strings are: "debug", "info", "warn", "error" or "off". To see the browser logs, you need to either show the log window in GUI mode, or enable browser-side logging in Selenium RC. 'logLevel' is one of the following: "debug", "info", "warn", "error" or "off"

设置浏览器端得日志信息阈值;在此阈值下的日志信息将被丢弃。可用的logLevel有: "debug", "info", "warn", "error" or "off".想要查看日志,可以在GUI模式下的显示日志窗口,或者使能seleniumRC的浏览器端日志。

138   run_script(self, script)

Creates a new "script" tag in the body of the current test window, and adds the specified text into the body of the command. Scripts run in this way can often be debugged more easily than scripts executed using Selenium's "getEval" command. Beware that JS exceptions thrown in these script tags aren't managed by Selenium, so you should probably wrap your script in try/catch blocks if there is any chance that the script will throw an exception. 'script' is the JavaScript snippet to run

在当前测试窗口的body中新建script标签,并且在命令body中添加特定的文本。如此debug脚本要比在selenium中执行getEval更容易。JS的异常selenium是不会管理的,所以你需要在可能出现异常的脚本中自行添加try/catch块。

139   add_location_strategy(self, strategyName, functionDefinition)

Defines a new function for Selenium to locate elements on the page. For example, if you define the strategy "foo", and someone runs click("foo=blah"), we'll run your function, passing you the string "blah", and click on the element that your function returns, or throw an "Element not found" error if your function returns null. We'll pass three arguments to your function: • locator: the string the user passed in • inWindow: the currently selected window • inDocument: the currently selected document The function must return null if the element can't be found. 'strategyName' is the name of the strategy to define; this should use only letters [a-zA-Z] with no spaces or other punctuation. 'functionDefinition' is a string defining the body of a function in JavaScript. For example: returninDocument.getElementById(locator);

定义一个新函数,用来selenium定位页面中的元素。比如,如果你定义一个策略"foo",并且有人执行click("foo=blah"),我们就会执行你的函数,传递给你字符创"blah",并点击你函数返回的元素,如果函数返回为null则抛出异常。 我们将会传递3个参数给你的函数: ○ locator:用户传入的字符串 ○ inWindow:当前选择的窗口 ○ inDocument:当前选择的文件 当元素找不到时,函数必须返回null。 'strategyName'是要定义的策略的名称;要使用大小写字母,并且没有空格与标点。'functionDefinition'是JavaScript中函数定义体字符串。比如returninDocument.getElementById(locator);

140   capture_entire_page_screenshot(self, filename, kwargs)

Saves the entire contents of the current window canvas to a PNG file. Contrast this with the captureScreenshot command, which captures the contents of the OS viewport (i.e. whatever is currently being displayed on the monitor), and is implemented in the RC only. Currently this only works in Firefox when running in chrome mode, and in IE non-HTA using the EXPERIMENTAL "Snapsie" utility. The Firefox implementation is mostly borrowed from the Screengrab! Firefox extension. Please seehttp://www.screengrab.org and http://snapsie.sourceforge.net/ for details. 'filename' is the path to the file to persist the screenshot as. No filename extension will be appended by default. Directories will not be created if they do not exist, and an exception will be thrown, possibly by native code. 'kwargs' is a kwargs string that modifies the way the screenshot is captured. Example: "background=#CCFFDD" . Currently valid options: * background the background CSS for the HTML document. This may be useful to set for capturing screenshots of less-than-ideal layouts, for example where absolute positioning causes the calculation of the canvas dimension to fail and a black background is exposed (possibly obscuring black text).

保存当前窗口的所有内容到一个PNG文件中。 对比captureScreenshot命令,它截取当前显示器中显示的所有内容,并且只由RC引入。目前此方法只在运行chrome模式的Firefox中支持。

141   rollup(self, rollupName, kwargs)

Executes a command rollup, which is a series of commands with a unique name, and optionally arguments that control the generation of the set of commands. If any one of the rolled-up commands fails, the rollup is considered to have failed. Rollups may also contain nested rollups. 'rollupName' is the name of the rollup command 'kwargs' is keyword arguments string that influences how the rollup expands into commands

执行具有一个名字的一系列命令的rolllup,可选参数用来控制命令集的生成。如果rolled-up命令的任何一个失败,则rollup被认为失败。rollups中可能包含嵌入的rollup。 rollupName是rollup命令的名称。kwargs是影响rollup如何在命令中展开的关键参数字符串

142   add_script(self, scriptContent, scriptTagId)

Loads script content into a new script tag in the Selenium document. This differs from the runScript command in that runScript adds the script tag to the document of the AUT, not the Selenium document. The following entities in the script content are replaced by the characters they represent: < > & The corresponding remove command is removeScript. 'scriptContent' is the Javascript content of the script to add 'scriptTagId' is (optional) the id of the new script tag. If specified, and an element with this id already exists, this operation will fail.

在selenium文档中加载脚本内容到一个新的脚本标签中。此命令与runScript不同之处在于,runScript在AUT的文档中添加script标签,不是selenium文档。 下面的实体会被其所代表的内容而替代: < > & 相对应的删除指令是removeScript。 scriptTagId(可选)是新脚本标签的ID,如果指定的ID已经存在,那操作会失败。

143   remove_script(self, scriptTagId)

Removes a script tag from the Selenium document identified by the given id. Does nothing if the referenced tag doesn't exist. 'scriptTagId' is the id of the script element to remove.

从selenium中删除给定tag id的脚本。如果指定的tag不存在则什么都不做。

144   use_xpath_library(self, libraryName)

Allows choice of one of the available libraries. 'libraryName' is name of the desired library Only the following three can be chosen: * "ajaxslt" Google's library * "javascript-xpath" Cybozu Labs' faster library * "default" The default library. Currently the default library is "ajaxslt" . If libraryName isn't one of these three, then no change will be made.

指定可用库。 目前支持的库名有: * "ajaxslt" Google's library * "javascript-xpath" Cybozu Labs' faster library * "default" 当前默认的库为ajaxslt。

145   set_context(self, context)

Writes a message to the status bar and adds a note to the browser-side log. 'context' is the message to be sent to the browser

在状态栏中写入一条信息,在浏览器log中加入一条记录。

146   attach_file(self, fieldLocator, fileLocator)

Sets a file input (upload) field to the file listed in fileLocator 'fieldLocator' is an element locator 'fileLocator' is a URL pointing to the specified file. Before the file can be set in the input field (fieldLocator), Selenium RC may need to transfer the file to the local machine before attaching the file in a web page form. This is common in selenium grid configurations where the RC server driving the browser is not the same machine that started the test. Supported Browsers: Firefox ("*chrome") only.

为一个上传框赋值为fileLocator中的文件。 fileLocator是指向特定文件的URL。在文件被设置到fieldLocator前,seleniumRC会将文件传送到本机。对于RC server与启动测试浏览器不在同一个机子的selenium grid,这是一个常见配置。 目前只支持Firefox。

147   capture_screenshot(self, filename)

Captures a PNG screenshot to the specified file. 'filename' is the absolute path to the file to be written, e.g. "c:lahscreenshot.png"

截取一张PNG屏幕截图,保存到指定名称。

148   capture_screenshot_to_string(self)

Capture a PNG screenshot. It then returns the file as a base 64 encoded string.

截图PNG屏幕截图。返回base64编码的字符串。

149   captureNetworkTraffic(self, type)

Returns the network traffic seen by the browser, including headers, AJAX requests, status codes, and timings. When this function is called, the traffic log is cleared, so the returned content is only the traffic seen since the last call. 'type' is The type of data to return the network traffic as. Valid values are: json, xml, or plain.

返回浏览器可见的网络信息,包括header, ajax 请求,状态码和计时。调用此方法时,日志会被清除,所以返回的内容只是上次调用的内容。 type支持的类型有:json, xml 和 plain。

150   addCustomRequestHeader(self, key, value)

Tells the Selenium server to add the specificed key and value as a custom outgoing request header. This only works if the browser is configured to use the built in Selenium proxy. 'key' the header name. 'value' the header value.

使selenium服务器为out的请求header添加指定的K—V。 只在被设置使用selenium代理的浏览器中生效。

151   capture_entire_page_screenshot_to_string(self, kwargs)

Downloads a screenshot of the browser current window canvas to a based 64 encoded PNG file. The entire windows canvas is captured, including parts rendered outside of the current view port. Currently this only works in Mozilla and when running in chrome mode. 'kwargs' is A kwargs string that modifies the way the screenshot is captured. Example: "background=#CCFFDD". This may be useful to set for capturing screenshots of less-than-ideal layouts, for example where absolute positioning causes the calculation of the canvas dimension to fail and a black background is exposed (possibly obscuring black text).

下载一个当前窗口画面的截图,based64编码的PNG图片。 整个窗口画面被截取,包括不在当前显示器中的部分。 目前只工作在chrome模式下的Mozilla。

152   shut_down_selenium_server(self)

Kills the running Selenium Server and all browser sessions. After you run this command, you will no longer be able to send commands to the server; you can't remotely start the server once it has been stopped. Normally you should prefer to run the "stop" command, which terminates the current browser session, rather than shutting down the entire server.

关闭运行中的selenium服务器以及所有的浏览器会话。执行此命令后,你不可以再向服务器发送指令;你不能再远程启动服务器。通常情况下,你只需要执行stop指令就可以了,它会种植当前浏览器的会话,而不是关闭整个服务器。

153   retrieve_last_remote_control_logs(self)

Retrieve the last messages logged on a specific remote control. Useful for error reports, especially when running multiple remote controls in a distributed environment. The maximum number of log messages that can be retrieve is configured on remote control startup.

获得指定RC中的最后一个日志信息。对于错误报告很有用,特别是在分布式环境中运行多个RC。可获取的日志信息的最大数量在RC启动时设置。

154   key_down_native(self, keycode)

Simulates a user pressing a key (without releasing it yet) by sending a native operating system keystroke. This function uses the java.awt.Robot class to send a keystroke; this more accurately simulates typing a key on the keyboard. It does not honor settings from the shiftKeyDown, controlKeyDown, altKeyDown and metaKeyDown commands, and does not target any particular HTML element. To send a keystroke to a particular element, focus on the element first before running this command. 'keycode' is an integer keycode number corresponding to a java.awt.event.KeyEvent; note that Java keycodes are NOT the same thing as JavaScript keycodes!

模拟用户按下一个键,发送本机操作系统的keystroke。本函数调用java.awt.Robot类来发送keystroke;这个更准确的模拟在键盘上输入一个键。本命令不指定任何html元素。如果要想特定的元素发送键击,首先移动焦点到该元素,然后执行命令。 此处的keycode是指java.awt.event.KeyEvent中的键码;注意java键码与javascript的键码是不同的。

155   key_up_native(self, keycode)

Simulates a user releasing a key by sending a native operating system keystroke. This function uses the java.awt.Robot class to send a keystroke; this more accurately simulates typing a key on the keyboard. It does not honor settings from the shiftKeyDown, controlKeyDown, altKeyDown and metaKeyDown commands, and does not target any particular HTML element. To send a keystroke to a particular element, focus on the element first before running this command. 'keycode' is an integer keycode number corresponding to a java.awt.event.KeyEvent; note that Java keycodes are NOT the same thing as JavaScript keycodes!

模拟用户释放一个按压的键,发送本地操作系统的键击。

156   key_press_native(self, keycode)

Simulates a user pressing and releasing a key by sending a native operating system keystroke. This function uses the java.awt.Robot class to send a keystroke; this more accurately simulates typing a key on the keyboard. It does not honor settings from the shiftKeyDown, controlKeyDown, altKeyDown and metaKeyDown commands, and does not target any particular HTML element. To send a keystroke to a particular element, focus on the element first before running this command. 'keycode' is an integer keycode number corresponding to a java.awt.event.KeyEvent; note that Java keycodes are NOT the same thing as JavaScript keycodes!

模拟用户按下并释放键,发送本地操作系统的键击。

原创粉丝点击