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()
Related
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.
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.
I am trying to click on open application alert using Selenium, and I am getting this error
NoAlertPresentException: Message: no such alert
So basically I am trying to open zoom application from the browser
And here is my code:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
driver = webdriver.Chrome(executable_path='chromedriver/chromedriver')
driver.get("https://zoom.us/j/93459172503?pwd=QkhnMEQ0ZTRZd0grUVJkT2NudmlFZz09")
try:
WebDriverWait(driver, 5).until(EC.alert_is_present(), 'Timed out waiting for alerts to appear')
alert = driver.switch_to.alert
alert.accept()
print("alert accepted")
except TimeoutException:
print("no alert")
Thanks to NetworkMeister, I end up using default app method, Like the following:
1- Open Firefox and go to zoom URL, when Launch application appear choose zoom and click on remember my choice and click open link
2- Go to firefox and paste this about:support then search for Profile Folder and copy the path
3- Go to your code and add profile parameter to selenium driver and use the path you have copied
fp = webdriver.FirefoxProfile('C:/Users/ASUS//AppData/Roaming/Mozilla/Firefox/Profiles/0rgewd47.default-release')
driver = webdriver.Firefox(executable_path='geckodriver', firefox_profile=fp)
driver.get('https://zoom.us/j/93459172503?pwd=QkhnMEQ0ZTRZd0grUVJkT2NudmlFZz09')
Now zoom application will open automatically when you execute this code
Note: Firefox profile contains all of your browsing data, If you want to share your code I suggest creating a new Firefox profile, For more information look here
Because this is not a browser Alert, rather OS App selector, you cannot interact with it within Selenium.
See: Selenium C# How to handle Alert "Open Pick an app"?
You can prevent these App selectors by default by using the --disable-default-apps flag when starting up Chrome.
I encountered this problem my self.
Apparently this is related to the alert being OS level rather than being at a browser level.
The simplest solution I found is https://pypi.org/project/PyAutoGUI/ which allows you to pass an img of the button you want to click and then it locates it on the screen. You can call python directly from java.
Native java solution: https://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html
this allows you to automate stuff like "move mouse to position" -> "mouse click" etc.
EDIT: the main downside is that the webdriver cannot be run in headless mode as PyAutoGUI makes a screenshot of the screen to locate the button.
From what I noticed is that when you open any such link in the browser the URL changes a bit. With this you can figure out the link for opening it in the browser. For example I have this zoom meeting
https://us04web.zoom.us/ w/ 76919011107?tk=5Q_zikLZhvWlqc_nzVcYaHoTyo7JuDY6cvLB9y9t0zc.DQIAAAARDLr3IxZHM21mSHFzYlR6Q0xZdnNhcnUwbUV3AAAAAAAAAAAAAAAAAAAAAAAAAAAA&pwd=QANkcTdsNlpjYWY4czZvd3FHV0NLQT09
Now this would open a popup like you showed in the browser. (This link is not real. I changed 2-3 characters in the URL for security reasons). But now if you try this link
https://us04web.zoom.us/ wc/join/ 76919011107?tk=5Q_zikLZhvWlqc_nzVcYaHoTyo7JuDY6cvLB9y9t0zc.DQIAAAARDLr3IxZHM21mSHFzYlR6Q0xZdnNhcnUwbUV3AAAAAAAAAAAAAAAAAAAAAAAAAAAA&pwd=QANkcTdsNlpjYWY4czZvd3FHV0NLQT09
This will directly open the meeting in the browser. Note the change in URL has been shown in bold (I had to add spaces because of that on both sides). Now this may change over time but fundamentally by comparing the 2 links you should find a way to achieve this.
Similarly for Microsoft Teams if you add "_#" after the domain you can join the meeting through the browser
For example if I want to open this link in the browser
https://teams.microsoft.com/l/meetup-join/19%3ameeting_NTRlM2JiZWUtZjNiMC00ZjVhLTlmMWEtZDcxYjBmYjdhY2Nl%40thread.v2/0?context=%7b%22Tid%22%3a%22e85f2c00-2730-4ca5-b8d8-609b15bd4746%22%2c%22Oid%22%3a%223bf1c992-96b1-4a87-808f-dcc5bb2009c9%22%7d
I'll have to write
https://teams.microsoft.com/_#/l/meetup-join/19%3ameeting_NTRlM2JiZWUtZjNiMC00ZjVhLTlmMWEtZDcxYjBmYjdhY2Nl%40thread.v2/0?context=%7b%22Tid%22%3a%22e85f2c00-2730-4ca5-b8d8-609b15bd4746%22%2c%22Oid%22%3a%223bf1c992-96b1-4a87-808f-dcc5bb2009c9%22%7d
These patterns can be found by observing the link before and after opening it in the browser.
This is not the best way but I resolved the issue by sending keyboard commands. It works on Windows, I haven't tested on different os.
import pyautogui
sleep(3) # sleep until pop up shown
pyautogui.press('tab', presses=2) # navigate to open button
pyautogui.press('enter') # open application
For me using Robot class worked for teams.
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
I'm trying to solve a little problem.
There is a web page - there is a button on this web page. When I click on this button, a new window is opened.
I'm curious, how to tell the Selenium that I want to see a page source of this new window?
You need to switch to the other window. Since the webdriver can only deal with your existing windows , you need to look into the window handling. You can find an example regarding switching windows below:
WebDriver driver = new FirefoxDriver();
driver.get("https://hdfcbank.com");
Thread.sleep(6000L);
Actions mouse = new Actions(driver);
WebElement address = driver.findElement(By.xpath("html/body/div[1]/div[2]/div[2]/div[2]/ul/li[7]/div[1]/span"));
mouse.moveToElement(address).build().perform();
Thread.sleep(2000L);
String parenthandle = driver.getWindowHandle(); // current window handle
driver.findElement(By.cssSelector("a[href*='goldloan']")).click();
Thread.sleep(5000L);
for (String windowhandle : driver.getWindowHandles()) {
driver.switchTo().window(windowhandle); // switches to next window
}
driver.findElement(By.xpath(".//*[#id='txtFName']")).sendKeys("testing");
driver.close();
driver.switchTo().window(parenthandle);
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.