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

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")

Related

Is there any way to get text from an element on current browser in python?

the thing is I can login to the site only from one device, which is my browser so I can't use selenium, so I have to use something else which opens my browser and copy the text from an element using python.
I think that you may use one of two solutions:
use selenium to open a browser every time, and automate the login process.
If the site allows you to access without logging in when you access with your default browser(such as Stack Overflow for example - you don't need to login every time you open the website from your device), you can use the same browser profile and it should do the same job - login automatically to that website.
references:
what's a browser profile?
how to load a chrome's browser profile with python3 and selenium?

how to get Selenium to get other tab information

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.

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()

Keys.ESCAPE in selenium webdriver(python)

I am using selenium webdriver (with python). I have a use case where I want to test that submit button get disabled once the form get submited. To test it, I send ESCAPE key to stop the page to load next page so that I can access the elements of same page.
password.send_keys("abcdef", Keys.ENTER, Keys.ESCAPE)
The problem is that it works fine in Firefox browser but it is not working in Chrome. In Chrome sending ESCAPE seems to be not working and it submits the form and loads the next page.
Is there any other solution or workaround to overcome this?
After trying many options, finally the following option seems to be working -
password.send_keys("abcdef", Keys.ENTER, Keys.ESCAPE) # this works for Firefox driver
drive.execute_script("window.stop();") # this works for Chrome driver
You can try one of these 3 suggestions from https://sqa.stackexchange.com/a/6208 :
Installing an extension in Chrome called Stop load
using the built in pageLoadTimeout() method in Selenium
using Sikuli or Autoit to access the browser's native controls

How to switch Firefox profile with Selenium - without instantiating a new driver?

Trying to find a way to switch the active profile in a Selenium Firefox driver. This question about multiple Firefox profiles states that creating and using multiple profiles is possible. However, it would be better if there were some way to switch the active Firefox profile within the driver session - instead of starting a new one.
How can I switch the active Firefox profile with Selenium?
Thanks very much!
You can't. Selenium does not let you change Firefox profiles, and I'm pretty sure even Firefox doesn't.

Categories

Resources