Python Selenium with Chrome. How to switch between different tabs

北慕城南 提交于 2021-02-07 10:24:42

问题


I click a button which opens a new tab. How to I then navigate around the new tab?

This sounds like a simple task but after several hours trying to find a solution I'm not any closer. Is there a simple way of doing this?

Tried using keys for CONTROL + 'T' and read other suggestions but nothing seems to work.

Many thanks


回答1:


I just implemented my solution and it worked for my case, which looks very similar to yours.

First you need to check the window_handles:

len(driver.window_handles) > 1

If you have more than one, you can try to switch to your second handler:

driver.switch_to_window(driver.window_handles[1])


来源:https://stackoverflow.com/questions/38948190/python-selenium-with-chrome-how-to-switch-between-different-tabs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!