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
Related
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?
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()
I am trying to get the current url opened in my pc in any browser using python.
I tried selenium it worked but it opens up a new browser window. I only want to get the current url opened in the browser.
Any help would be appreciated.
use keylogger in python, that would easiest solution, orelse you should catch each and every packets in network.
Selenium isn't made for such purposes. It can be used to automate testing of websites or for website scraping. Selenium associated with a driver (like Chrome's driver for example) is just a fancy browser that let's you interact with it in a non-intrusive way.
If you need to interact with already running apps, you could attach to another process's memory and read stuff directly from there but it might be very messy.
Also, see: Interact with other programs using Python
I tried to write code to login using pywinauto and selenium, but my script is getting failed. I tried to find solution, but it seems there is no much info available on this.
from pywinauto import application
from selenium import webdriver
driver=webdriver.Chrome()
app=application.Application()
driver.get("https://google.co.in")//url for google only as an example
app = application.Application()
app.connect(backend="uia") // getting issue in this line, what to write under bracket to connect to opened browser?
app.window_().TypeKeys('username') // Is this proper way to type text in authentication window username field where cursor blinks by default?
I am getting below error message
pywinauto.findwindows.ElementAmbiguousError: There are 6 elements that
match the criteria {'backend': u'win32'}
Note : For login to my application, windows authentication popup appears which cannot be handled in selenium, so need to handle it using other tool. I had a solution to it earlier which is not working now, I had asked it here Windows authentication code no longer working now
The steps your need are; open the page, find the elements you want to interact with (such as login text box) then type your input. This can all be done in selenium. Check out the documentation:
http://selenium-python.readthedocs.io/navigating.html#interacting-with-the-page
The component which needs to be automated is antd - upload.
https://ant.design/components/upload/ --> Can be found here
The button for the upload is visible, but the input "tag" is not visible:
Component view: This is the button how it is seen on the screen
HTML view: This is the view of the inspection of the component
As you see the "input" is not visible.
To have selenium interact with the input (to use the sendkeys) I need to have the input element visible on the screen.
I make an execute script as follows:
file_input = self.driver.find_element_by_xpath(xpath)
self.driver.execute_script('arguments[0].style.display = "block"; ', file_input)
After this I get the following view of the component: component ui view
And the html view: HTML view
After this I interact with the component by sending keys to the element:
file_input.send_keys(fpath)
At this step I have 2 things happening:
1. the file selector popup is shown
2. the file is uploaded by the send_keys.
This causes an issue when I try to run the scripts in headless browser. The message that is shown:
SessionNotCreatedException: Message: Tried to run command without establishing a connection headless browser
This is only due to running in headless browser mode. When the browser is displayed, the scripts are kept going. I have also tried using on both displayed and headless browser the module pyautogui:
pyautogui.keyDown('esc')
pyautogui.keyUp('esc')
This helps only on the displayed browser, so the popup is closed. But for headless browser this doesn't help.
I am running the scripts on MacOS Sierra, Firefox (58.0.2) in headless browser options, python 2.7, selenium 3.8
Would be very grateful if someone knows how to work around this.
Thank you
Update with the latest chromedriver and chrome. This is working without having a popup come out for headless browser when running this step by send-keys in selenium.
Firefox still has this issue with geckodriver.