how to get Selenium to get other tab information - python

As it stands and I speak under correction, selenium opens a "private" browser tab.
I wanted to know if there was any way to change that so that the selenium tab can benefit from other tabs that are open, i.e. not need to login because you are already logged in on another non-selenium tab

I think the problem is that Selenium loads up the default browser profile. If you use chrome or a chromium based browser, go to chrome://version and you should see a heading called Profile Path copy that and add it to your program with the options method.
Here is a sample:
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=path_to_chrome_profile") #Path to your chrome profile
driver = webdriver.Chrome(executable_path="path_to_chromedriver", chrome_options=options)
Hope it helps. And yes, make sure you are signed into the account you want selenium to access when you check your path.

Related

Need help python open browser using specific profile

Still new to a Python.
I need to be able to open a Chrome browser with specific profile.
And verify that proper the page is opened, by specific element on a page
Use selenium to control the browser from python.
https://selenium-python.readthedocs.io/getting-started.html#simple-usage
You can use the chrome driver that you download from https://chromedriver.chromium.org/downloads
You will use XPATH to locate the elements and validate the page
https://selenium-python.readthedocs.io/locating-elements.html

how to open multi tabs in chrome with selenium with different session

I need to login to multiple accounts (same website) at once and I need to open multiple tabs.
Each tab needs to be independent so that I can login to different accounts.
is there any way to achieve this using selenium or any other automation tool.
Greetings.
yes indeed you can by using chrome driver and selenium
code:
driver= webdriver.Chrome(executable_path="ChromeDriverExeLocation")
driver1= webdriver.Chrome(executable_path="ChromeDriverExeLocation")
driver.get("googleloginform")
driver1.get("googleloginform2")

How do you stay logged in with the Selenium Chrome browser?

I use the following code to open a Chrome window using Selenium:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.youtube.com/")
However, whenever I enter the site, I am logged out. On other sites, I can manually do so, but Google deems it unsafe to log in with Selenium.
I know that Selenium is a test browser, but is it possible to stay logged in with Selenium so that I can access my user data; or is that not the purpose of Selenium, and calling the Chrome subprocess the way to go?
To start with Selenium isn't a browser as such but a bunch of libraries which helps in simulating Browsing Context.
From the question it's not that clear why you are logged out once you login in to the site. But definitely once you are logged in using Selenium driven ChromeDriver initiated google-chrome Browsing Context you must remain logged in and should be able to access your user data.

Python: How to automate 'Allow' flash player content in Firefox?

I need to allow flash content in an automated manner in Python. I tried using Selenium in Python to do so but could not manage. The issue is that browsers stopped supporting settings that always allow flash content. Moreover, the "Allow" button cannot be accessed via Selenium for instance because it is not a part of the website or a setting in Firefox. Does anyone know about a potential workaround?
Here is an image of the Firefox message that I need to somehow access:
"...The Allow button cannot be accessed via Selenium for instance because it is not a part of the website or a setting in Firefox. Does anyone know about a potential workaround?"
I don't know your OS but if it was my problem...
Try to find a "key press" module to send the A key press into Firefox (ie: the Allow shortcut).
Try to send a mouse-click at the coordinates of Allow button.
A good option to try is pyautogui. Once Flash is enabled by such module (clicker or presser) then you can involve Selenium for whatever you needed to do in the enabled Flash.
To allow flash content in an automated manner using Selenium through Python you need to use an instance of FirefoxProfile() and set_preference() method to configure:
dom.ipc.plugins.enabled.libflashplayer.so to true
plugin.state.flash to 2
Code Block:
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference("dom.ipc.plugins.enabled.libflashplayer.so","true")
profile.set_preference("plugin.state.flash", 2)
driver = webdriver.Firefox(firefox_profile=profile, executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
driver.quit()

Using Selenium/WebDriver and Python, how do I suppress the prompt to share my camera and microphone?

I am using Selenium in Python to automate a remote browser. The browser needs access to its webcam and microphone. When I navigate to a page that requests access, Firefox shows a pop-up window that asks "Would you like to share you camera and microphone with [host]?"
This window is not part of the browser's page, so it cannot be detected or controlled via Selenium.
This behavior is controlled by the media.navigator.permission.disabled option in Firefox's 'about:config' page. If this option is set to 'true', then access to the camera should be granted automatically.
When I set that option to 'true', it eliminates the prompt only when I run Firefox manually. When I run Firefox via Selenium, I still get the prompt.
How can I suppress this prompt, and have permission granted automatically?
The problem lies in Firefox profiles. Selenium creates a new, temporary profile for each browser instance. This profile is separate from the profile you use when you manually start Firefox.
Thus, when you set media.navigator.permission.disabled to 'true' in about:config, you do so only for your profile, and not for the profile that Selenium uses.
There are two ways to work around this:
Tell Selenium which existing profile to use.
To do this, you must first determine which profile you are using. To do this, close all instances of Firefox, then execute firefox -p to start the profile manager. In most cases, you will see a single profile called default.
Using this profile, navigate to about:config, and set the media.navigator.permission.disabled option to true.
Then, when you start the Selenium standalone server, specify this profile:
java -jar selenium-server-standalone-2.37.0.jar -Dwebdriver.firefox.profile=default
This tells Selenium to use the default profile, which has the settings you want.
Create and configure a new profile for Selenium to use.
Before you create the browser instance, you must create a Firefox profile and configure it to meet your needs:
profile = webdriver.FirefoxProfile()
profile.set_preference ('media.navigator.permission.disabled', True)
profile.update_preferences()
Then specify this profile when you create the remote browser instance:
firefox = selenium.webdriver.remote.webdriver.WebDriver (command_executor=my_url, desired_capabilities=DesiredCapabilities.FIREFOX, browser_profile=profile)
Selenium will then use this profile, and you should not be prompted for permission to access the camera.
Note that this method takes more time than the first method.
You can use options:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.set_preference("media.navigator.permission.disabled", True)
browser = webdriver.Firefox(options=options)

Categories

Resources