VBA Selenium switch to parent tab.

Adeel1

New Member
Joined
Sep 29, 2019
Messages
29
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
i have below code after opening multiple tabs i want to switch to parent tab, below isn't working, TIA

VBA Code:
Sub tabs()
bot.Get "https://www.google.com/"

For i = 1 To 3
bot.ExecuteScript "window.open('https://www.wikipedia.com')"

bot.Wait 300
bot.SwitchToNextWindow

bot.FindElementByXPath("//input[@id='searchInput']").SendKeys "ImranKhan"

bot.Wait 200

bot.FindElementByXPath("//i[@class='sprite svg-search-icon']").Click

Next i
bot.SwitchToParentFrame
'bot.SwitchToPreviousWindow

bot.FindElementByXPath("//textarea[@class='gLFyf']").SendKeys "nabeelGondal"
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Do you mean switch to the first tab? If so, try:
VBA Code:
    bot.SwitchToWindowByTitle "Google"

Oddly, the following equivalent doesn't work:
VBA Code:
    bot.SwitchToWindowByTitle bot.Windows(1).Title
It flashes between tabs 2-4 and errors out with "Window not found: Google".
 
Upvote 0
VBA Code:
Sub tabs()
    bot.Get "https://www.google.com/"
    
    Dim windowTitle As String
    windowTitle = bot.Window.Title
    
    For i = 1 To 3
        bot.ExecuteScript "window.open('https://www.wikipedia.com')"
        
        bot.Wait 300
        bot.SwitchToNextWindow
        
        bot.FindElementByXPath("//input[@id='searchInput']").SendKeys "ImranKhan"
        
        bot.Wait 200
        
        bot.FindElementByXPath("//i[@class='sprite svg-search-icon']").Click
    
    Next i
    
    bot.Window.SwitchToWindowByTitle windowTitle
    
    bot.FindElementByXPath("//textarea[@class='gLFyf']").SendKeys "nabeelGondal"
    
    Do While True: DoEvents: Loop
End Sub
 
Upvote 0
thx John for your support.

this works >>
bot.SwitchToWindowByTitle "Google"

base on your second idea below works.

bot.Windows(1).Activate
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top