[英]Opening new tab with selenium python(3) and performing functions on it
Take an example of Facebook 以Facebook为例
I have the main page in the driver object 我在驱动程序对象中有主页
I have the url of the element I want to access(comments of first post) 我有我要访问的元素的URL(第一篇文章的评论)
1 how can I open it another tab 1如何打开另一个标签
2 will this new tab be saved in some sort of object just like driver(so that I can perform actions on it) 2这个新标签页会像驱动程序一样保存在某种对象中(以便我可以对其执行操作)
I have reached the solution. 我已经解决了。
For getting button of the desired link we can do this: 为了获得所需链接的按钮,我们可以这样做:
button = driver.wait.until(EC.visibility_of_element_located((By.NAME,'login' )))
when you have the button that you want to click then do this 当您具有要单击的按钮时,请执行此操作
storyButton.send_keys(Keys.CONTROL + Keys.RETURN)
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.TAB)
for transferring control to the second tab we can do this 为了将控制权转移到第二个选项卡,我们可以执行此操作
tabs = driver.window_handles #creates a list of tabs
driver.switch_to_window(tabs[1]) #switches driver control to the second tab
now every thing will be done in the second tab until controls are shifted back to the first tab 现在,所有操作都将在第二个选项卡中完成,直到控件移回到第一个选项卡
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.