Pyton Splinter Selenium Firefox Click "Display the progress of ongoing downloads" Button - python

Firefox (recently) has decided that we need to see an obnoxious list of downloads at the top right of the browser, even if we do not ask for it. There are work-arounds, which I have tried (going to about:config in the browser and adjusting settings). I have also tried this in my code itself:
from splinter import Browser
browser = Browser()
browser.driver.profile.DEFAULT_PREFERENCES['frozen']["dom.disable_open_during_load"] = True
browser.driver.profile.DEFAULT_PREFERENCES['frozen']['dom.webnotifications.enabled'] = False
browser.driver.firefox_profile.set_preference("browser.download.alwaysOpenPanel", False)
None of the above works. At this point, if I can just get Splinter to click on the "Display the progress of ongoing downloads" button at the top right, my life would be much easier. Is this possible?
I'm using Firefox 104.0.2, Splnter 0.16.0, and Python 3.10.6. I also have Selenium 3.141.0.

Related

*** Solved *** Python - Displaying a web site in the same browser tab each time webbrowser.open is called

In Python, I would like to initially open a new browser tab and display a web site. The program will be displaying other png images before cycling back to displaying the web site again. It's like a slide show. I tried to use the webbrowser.open statement displayed below to open the web site with the "New" parameter equaling 1 expecting a new tab not to be opened, but every time webbrowser.open is called, a new tab opens on the Chrome browser.
Can you tell me what coding is needed to ensure once a tab is opened in the browser, additional calls to webbrowser.open won't open new tabs for the web site?
webbrowser.open('https://mawaqit.net/en/abricc-acton-01720-united-states', new=1)
the docs says
webbrowser.open(url, new=0, autoraise=True)
Display url using the
default browser. If new is 0, the url is opened in the same browser
window if possible. If new is 1, a new browser window is opened if
possible. If new is 2, a new browser page (“tab”) is opened if
possible. If autoraise is True, the window is raised if possible (note
that under many window managers this will occur regardless of the
setting of this variable).
Nothing here says that it can replace or close the current tab, so I am afraid that you will have to use something like Selenium instead.
I'm unfamiliar with the webbrowser tool, but using selenium webdriver the following all stays in the same tab.
# import
from selenium import webdriver
from selenium.webdriver.common.by import By
# browser setup
browser = webdriver.Chrome()
browser.implicitly_wait(10)
# open url
browser.get("http://www.google.com")
# click element on page (same tab)
browser.find_element(By.XPATH,"/html/body/div[1]/div[1]/div/div/div/div[1]/div/div[2]/a").click()
# open new URL (same tab)
browser.get("http://www.stackoverflow.com")
Also, some other tools available in selenium are below. These are useful if you want new tabs but need to switch back and forth to "parent" tabs:
# assign tab variables (window_handle = tab apparently)
window = browser.current_window_handle
parent = browser.window_handles[0]
child = browser.window_handles[1]
# switch to new tab
browser.switch_to.window(parent)
I hope that at least some element of this is helpful.

Selenium exits fullscreen when clicking at a link

The Selenium web driver exists fullscreen whenever clicking at a link or opening a new URL.
Any remedies to force fullscreen?
*I am using the fullscreen_window() method.
Google Chrome 91 /
Linux KDE Neon
Let's say when you click on a link like this :
driver.find_element_by_xpath('some xpath').click()
and a new tab opens up :
and then you switch it like this :
driver.switch_to.window(hadles[1])
it would not open screen in full size, you would need to again do this :
driver.maximize_window()

Is it possible to start Firefox via PythonSelenium in a way that the menu bar is displayed from the beginning?

I am (as a newbie) experimenting with Python and Selenium.
I have managed to write a script that starts Firefox via Selenium and logs into the websites I need for work using my IDs and passwords:
usr='xxx'
pwd='xxx'
# firefox öffnen und seite öffnen
driver=webdriver.Firefox()
driver.get('https://www.site-online.de')
#username usr eintragen
username_box=driver.find_element_by_id('username')
username_box.send_keys(usr)
#pw pwd1 eintragen
pwd_box=driver.find_element_by_id('passwd')
pwd_box.send_keys(pwd)
Great so far. However I note that the Firefox browser does not initially display the Menu Bar at the top (File, Edit, View...).
I have found out that it can be activated by a right click in the top region of the browser. However, is there a way to activate the menu bar directly by the Python script?
Thank you for any answer.
TACologne

selenium window_handles not correct when new window is opened wtih Python

I want to use selenium with Python to open multi-tabs in one browser and scraping the real-time betting odds simultaneously with multi-tabs.
The website home page generate a list of games. However, there is no way to get the link of game unless you find the game element and use click()(the website is ajax heavy), which open the game in the same tab. My solution to open multi-tabs is to get the list of game then manually open new tab with home-page first loaded and then click on the game with different index in the list. However, I find the driver.window_handles array always include only one item, which is the current tab instead of all the tabs I opened manually in the browser.
Can anybody tell me what goes wrong or if you can give a better solution to this issue?
The problem is simplified as the code in following:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# create a new Firefox session
driver_temp = webdriver.Firefox()
driver_temp.implicitly_wait(30)
driver_temp.get("https://www.google.com")
body = driver_temp.find_element_by_tag_name('body')
# manually open second tab
body.send_keys(Keys.CONTROL + 't')
driver_temp.get("https://www.google.com")
body = driver_temp.find_element_by_tag_name('body')
# manually open third tab
body.send_keys(Keys.CONTROL + 't')
driver_temp.get("https://www.google.com")
body = driver_temp.find_element_by_tag_name('body')
#print the number of window_handles
print len(driver_temp.window_handles)
I have opened 3 tabs, however the len(driver_temp.window_handles) is always 1
Selenium does not provide an API to manipulate browser tabs. You've probably noticed that applying the CTRL/COMMAND+T "hack" to open a new tab.
See more at:
Controlling firefox tabs in selenium
Opening a new tab in the same window session of the browser through selenium web driver command?
Instead, open up new browser windows.
Well, to be fair, it is important to mention that the behavior is quite different in Firefox and in Chrome - if you open new tabs in Chrome, selenium would see each tab as a window with it's own handle and you'll switch between them using switch_to.window() easily.

blocking pop-ups resulting from selenium firefox driver

I am attempting to scrape websites using selenium-python. I am trying to use firefox driver (since PhantomJS doesn't work on me), but is there way to block the pop-ups when using the firefox driver?
thank you
Even I turn on "disable pop ups" in FireFox manually, it's not working for all website. A work around is switch to pop up window, close it, and switch back to the original window.
Here is the code in python:
# Switch to new window opened
driver.switch_to.window(driver.window_handles[-1])
# Close the new window
driver.close()
# Switch back to original browser (first window)
driver.switch_to.window(driver.window_handles[0])
Sorry for the late answer, but you can use the dom.popup_maximum profile preference, setting it to 0 like this:
from selenium import webdriver
fp = webdriver.FirefoxProfile()
fp.set_preference("dom.popup_maximum", 0)
driver = webdriver.Firefox(firefox_profile=fp)
url = "http://some.url.with.annoying.popups"
driver.get(url)
For a list of other available options, please refer to this answer
Use xvfb in the framebuffer and here is a simple usage.
It provides an X environment for selenium.

Categories

Resources