robot framework窗口切换

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了robot framework窗口切换相关的知识,希望对你有一定的参考价值。

参考技术A 这里暂做个记录,问题先解决到这里,后期如果能完善该问题再来更新

疑问: robot framework中通过browser.switch_to_handle(handle)进行窗口切换时候,程序是正常切换了,但是浏览器上展示的当前窗口并没有切换

目标:在浏览器窗口A上有个链接,点击后同一浏览器打开窗口B,在A和B窗口之间互相切换,并获取对应窗口的元素

def select_by_handle(self,browser,handle):

    browser.switch_to_window(handle)

print "toHandle: "+ handle

def get_window_handles_bylh(self,browser):

    return [window_info[0]forwindow_infoinself._get_window_infos(browser)]

def get_current_window_handle_bylh(self,browser):

    return browser.get_current_window_handle()

def select_window_by_handle(self,locator=None):

    self._window_manager.select_by_handle(self._current_browser(),locator)

def get_window_handles_bylh(self):

    """Returns and logs handles of all windows known to the browser."""

    return self._log_list(self._window_manager.get_window_handles_bylh(self._current_browser()))

def get_current_window_handle_bylh(self):

    """Returns and logs handle of current window known to the browser."""

    return self._log_list(self._window_manager.get_current_window_handle_bylh(self._current_browser()))

1.通过get window handles bylh方法获取当前浏览器中A和B窗口的句柄

2.通过select_window_by_handle从A窗口切换到B窗口,获取B窗口中的元素

浏览器中的页面从A窗口跳转到B窗口,元素获取成功获取

1.通过get window handles bylh方法获取当前浏览器中A和B窗口的句柄

2.通过select_window_by_handle从A窗口切换到B窗口

3.再次通过select_window_by_handl从B窗口切换到A窗口,获取A窗口中的元素

浏览器中页面上还是展示B窗口,但能正常获取到A窗口中的元素

1.通过get window handles bylh方法获取当前浏览器中A和B窗口的句柄

2.通过select_window_by_handle从A窗口切换到B窗口

3.再次通过select_window_by_handl从B窗口切换到A窗口,获取B窗口中的元素

浏览器中页面上先是展示B窗口,等到获取B窗口中的元素失败后,浏览器中的窗口切换到A窗口

三个场景中获取浏览器的get window handles bylh和select_window_by_handle方法都正常

Robot Framework应用——Mac环境下Robot Framework的安装及简单实用

转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/116591032
本文出自【我是干勾鱼的博客

下载robotframework

$ pip install robotframework
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting robotframework
  Downloading robotframework-4.0.1-py2.py3-none-any.whl (655 kB)
     |████████████████████████████████| 655 kB 15 kB/s 
Installing collected packages: robotframework
Successfully installed robotframework-4.0.1

下载docutils

$ pip install docutils
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting docutils
  Downloading docutils-0.17.1-py2.py3-none-any.whl (575 kB)
     |████████████████████████████████| 575 kB 17 kB/s 
Installing collected packages: docutils
Successfully installed docutils-0.17.1

查看robot版本

$ robot --version
Robot Framework 4.0.1 (Python 2.7.10 on darwin)

下载robotframework-ride

$ pip install robotframework-ride
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting robotframework-ride
  Downloading robotframework-ride-1.7.4.2.tar.gz (846 kB)
     |████████████████████████████████| 846 kB 1.9 MB/s 
Collecting wxPython<=4.0.7.post2
  Downloading wxPython-4.0.7.post2-cp27-cp27m-macosx_10_9_x86_64.whl (16.9 MB)
     |████████████████████████████████| 16.9 MB 543 kB/s 
Collecting PyPubSub
  Downloading PyPubSub-3.3.0.zip (87 kB)
     |████████████████████████████████| 87 kB 2.0 MB/s 
Collecting Pygments
  Downloading Pygments-2.5.2-py2.py3-none-any.whl (896 kB)
     |████████████████████████████████| 896 kB 1.2 MB/s 
Collecting numpy<1.17; python_version <= "2.7"
  Downloading numpy-1.16.6-cp27-cp27m-macosx_10_9_x86_64.whl (13.9 MB)
     |████████████████████████████████| 13.9 MB 2.6 MB/s 
Collecting pillow
  Downloading Pillow-6.2.2-cp27-cp27m-macosx_10_6_intel.whl (3.9 MB)
     |████████████████████████████████| 3.9 MB 2.4 MB/s 
Collecting six
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Building wheels for collected packages: robotframework-ride, PyPubSub
  Building wheel for robotframework-ride (setup.py) ... done
  Created wheel for robotframework-ride: filename=robotframework_ride-1.7.4.2-py2-none-any.whl size=950980 sha256=0f6731366cd527a42d814ce37e9e38c5168270a6c5ffdc09760eac832d5064fd
  Stored in directory: /Users/yuhaidong/Library/Caches/pip/wheels/94/e1/c4/dc60488f661a4037adf76d39a490e74950e16919be1ed49d75
  Building wheel for PyPubSub (setup.py) ... done
  Created wheel for PyPubSub: filename=PyPubSub-3.3.0-py2-none-any.whl size=80830 sha256=24fc86e451775032cf302304bb6e618515919ba5923b1a1c1956745e23cbd11d
  Stored in directory: /Users/yuhaidong/Library/Caches/pip/wheels/7c/fb/b6/1728423876af6e29b6a8971bf8a5f03b34c890e03489accb12
Successfully built robotframework-ride PyPubSub
Installing collected packages: numpy, pillow, six, wxPython, PyPubSub, Pygments, robotframework-ride
Successfully installed PyPubSub-3.3.0 Pygments-2.5.2 numpy-1.16.6 pillow-6.2.2 robotframework-ride-1.7.4.2 six-1.16.0 wxPython-4.0.7.post2

下载robotframework-selenium2library

$ pip install robotframework-selenium2library
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting robotframework-selenium2library
  Downloading robotframework_selenium2library-3.0.0-py2.py3-none-any.whl (6.2 kB)
Collecting robotframework-seleniumlibrary>=3.0.0
  Downloading robotframework_seleniumlibrary-4.5.0-py2.py3-none-any.whl (89 kB)
     |████████████████████████████████| 89 kB 570 kB/s 
Collecting robotframework-pythonlibcore>=2.1.0
  Downloading robotframework_pythonlibcore-2.2.1-py2.py3-none-any.whl (10 kB)
Collecting selenium>=3.141.0
  Downloading selenium-3.141.0-py2.py3-none-any.whl (904 kB)
     |████████████████████████████████| 904 kB 1.7 MB/s 
Requirement already satisfied: robotframework>=3.1.2 in /Users/yuhaidong/py_virtualenv/rpa/lib/python2.7/site-packages (from robotframework-seleniumlibrary>=3.0.0->robotframework-selenium2library) (4.0.1)
Collecting urllib3
  Downloading urllib3-1.26.4-py2.py3-none-any.whl (153 kB)
     |████████████████████████████████| 153 kB 2.8 MB/s 
Installing collected packages: robotframework-pythonlibcore, urllib3, selenium, robotframework-seleniumlibrary, robotframework-selenium2library
Successfully installed robotframework-pythonlibcore-2.2.1 robotframework-selenium2library-3.0.0 robotframework-seleniumlibrary-4.5.0 selenium-3.141.0 urllib3-1.26.4

以上是关于robot framework窗口切换的主要内容,如果未能解决你的问题,请参考以下文章

robot framework appiumlibrary 怎么获取窗口大小

Python + Robot Framework 环境搭建

appium+robot framework 一个测试用例

Uncaught InvalidArgumentException: Please provide a valid cache path. in /apps/vendor/laravel/framew

Robot Framework应用——Mac环境下Robot Framework的安装及简单实用

Robot Framework应用——Mac环境下Robot Framework的安装及简单实用