简体   繁体   中英

Selenium click chrome physical buttons like menu, left, right navigation, bookmarks

I'm working on a some automation work, as per my requirement I need to click on Chrome Physical buttons like left nav, right nav, bookmarks, menu etc. I can do with shortcuts but my requirement is to click on browser buttons. Any ideas would be helpful. Thanks in advance.

As per your question you want to click on Chrome Physical buttons like left navigation, right navigation, bookmarks, menu etc.

But if you look into the documentation in Selenium Home Page it clearly mentions that :

The entire suite of tools provided by Selenium results in a rich set of testing functions specifically geared to the needs of testing of web applications. These operations allow many options for locating UI elements and comparing expected test results against actual application behavior.

So factually Selenium by design interacts with the HTML DOM and the WebElements located in the DOM Tree

Now the desired controls eg left navigation , right navigation , bookmarks , menu are out of the DOM . Hence you cannot mock the click on those controls.

However all the Selenium Language Binding Art provides a handfull of methods to achieve the same result. Here are a few from the Selenium Python Binding Art :

  • Maximize : To maximize the browser window.

     driver.maximize_window() 
  • Minimize : To minimize the browser window.

     driver.minimize_window() 
  • Close : To close the browser window.

     driver.close() 
  • Quit : To close the browser window gracefully.

     driver.quit() 
  • Refresh : To refresh the url.

     driver.refresh() 
  • Forward : To move forward.

     driver.forward() 
  • Back : To move backwards.

     driver.back() 
  • And of-coarse Get : To invoke an url .

     driver.get('http://google.com/') 

There are functions for this that is built-in:

driver.forward()
driver.back()

https://selenium-python.readthedocs.io/navigating.html#navigation-history-and-location

It doesn't appear that selenium can interact with the Bookmark, but let me check some more.

This can't be done with selenium webdriver and I think also not with the standalone selenium server. Selenium only allows to interact with the DOM.

The only way to achieve what you want to do is to use an automation tool that actually runs directly in the OS that you use. Java can be used to write such a program.

I would however recommend to not go this route. Instead try to convince whoever is responsible for your requirements to re-think and allow to use other means of achieving back and forward actions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM