How to access a new browser tab

好久不见. 提交于 2019-12-06 02:51:37

I would recommend using watir-webdriver on tab handling:

Try the following

MEDBEDbs-iMac:~ medbedb$ irb
1.9.3p392 :001 > require 'watir-webdriver'
 => true 
1.9.3p392 :002 > b = Watir::Browser.new :chrome
 => #<Watir::Browser:0x..f87e94a30e87e1e60 url="about:blank" title="about:blank"> 
1.9.3p392 :003 > b.goto "http://www.w3schools.com/html/html_links.asp"
 => "http://www.w3schools.com/html/html_links.asp" 
1.9.3p392 :004 > b.title
 => "HTML Links" 

Here a new window is opened in a new tab.

1.9.3p392 :005 > b.a(:text, 'HTML links').click
 => [] 
1.9.3p392 :006 > b.windows.count
 => 2 

But watir-webdriving is still handling the previous page..

1.9.3p392 :007 > b.title
 => "HTML Links" 

Switching to recently opened tab.

1.9.3p392 :008 > b.windows.last.use
 => #<Watir::Window:0x..fd949289f2b083062 located=true> 
1.9.3p392 :009 > b.title
 => "Tryit Editor v1.7" 

From here you can do whatever you need in a new tab.

1.9.3p392 :010 > b.windows.last.close
 => #<Watir::Window:0x..fd949289f2b083062 located=true> 

After closing the new tab watir will switch back to initial tab.

1.9.3p392 :011 > b.title
 => "HTML Links" 
1.9.3p392 :012 > b.close
 => true 
Show us the code or url to the web-pate to get more detailed results...
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!