Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Firefox Selenium (open new tab)
#1
can any one tell me what are the methods to work with multiple tab in firefox using selenium & Py 3?
I have tried to open a new tab which is not happening ?

here are my code:
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
import requests

browser = webdriver.Firefox()
browser.get('http://www.google.com')
browser.find_element_by_tag_name('body').send_keys(Keys.COMMAND + 't')

search = browser.find_element_by_name('q')
i had tried this code but didnt worked, Am i doing anything wrong in this ??
Reply
#2
One way to do it is with javascript.

browser.execute_script("window.open();")
#or to open a url
#browser.execute_script("window.open('{}');".format(ulr))
Each tab has an identifier(handle), to list all handles use:
when new tab is opened its handle is appended to the list.


browser.window_handles
To access current handle(the tab where current code will execute) use:

handle=browser.current_window_handle

To switch to desired window use:


browser.switch_to.window(handle)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help for script access via webdriver to an open web page in Firefox Clixmaster 1 1,214 Apr-20-2023, 05:27 PM
Last Post: farshid
  Connect to existing Firefox session with Selenium euras 0 5,390 Feb-11-2021, 02:54 PM
Last Post: euras
  Selenium won't open a link Justin2444 2 5,773 Apr-07-2020, 09:46 AM
Last Post: Larz60+
  Unable to access javaScript generated data with selenium and headless FireFox. pjn4 0 2,501 Aug-04-2019, 11:10 AM
Last Post: pjn4
  selenium not running firefox Sanlus 5 4,820 Aug-31-2018, 10:37 PM
Last Post: snippsat
  open a web page by selenium !! evilcode1 3 3,289 Aug-01-2018, 03:05 PM
Last Post: snippsat
  Proxy Variable in Selenium wont work with FireFox Profile Proxy Setting. MIPython 0 8,491 Jul-13-2018, 05:43 PM
Last Post: MIPython
  How to geckodriver anonymous firefox mariolopes 5 7,121 Feb-10-2018, 10:58 PM
Last Post: mariolopes
  Selenium with headless firefox is slow mgtheboss 4 14,881 Jan-13-2018, 09:03 PM
Last Post: metulburr
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 3,587 Nov-03-2017, 08:41 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020