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.
Related
The project is a web page with another app embedded as an iframe and I'm trying to write a test to check that no errors are logged in the embedded app.
The issue is that get_log doesn't return the logs of the embedded app
log = driver.get_log('browser')
logger.info(log) # only contains the main page logs, and iframe logs are skipped
capabilities['goog:loggingPrefs'] = {'browser': 'ALL'}
is used when launching chrome.
Also tried with and without this before get_log but it makes no difference, even though driver.page_source does change correctly, and elements inside the iframe can be accessed normally.
driver.switch_to.frame(frame_id)
Still only the console log of the parent of the iframe are returned by get_log, but I also need the iframe logs, which are correctly shown in devtools in the chrome browser instance opened by selenium.
Any ideas or workarounds on how to load all of the logs into the python test?
Selenium 4.4.3
Python 3.9.2
Chrome (and chromedriver) 107.0.5304.87
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 working on selenium with python on raspberry pi. I have installed the iceweasel version of Firefox. I am following instruction from this video.
I have a website opened using selenium and I am trying to click on a link which will open a page on the website. Normally if I do it (without selenium), it works fine. But using selenium, its taking too long to open and the loading icon on website keeps on showing. Due to this below warning message comes up in browser which the python selenium code is not able to handle and crashes.
Below is the code:
DASHBOARD = (By.XPATH, data["Dashboard"]) # data["Dashboard"] is getting XPATH from config file
WebDriverWait(driver, 20).until(EC.element_to_be_clickable(DASHBOARD)).click()
print("Dashboard page clicked {}")
time.sleep(20)
In the above python code, selenium is clicking on dashboard page. As soon as this thing happens, I can see it getting clicked on the website too. But after this it keeps on loading and loading and then the Unresponsive script warning comes and it shows below error:
Script: https://<url>/asseā¦/angular/angular.js?20190904.1:9336) The alert could not be closed. The browser may be in a wildly inconsistent state, and the alert may still be open. This is not good. If you can reliably reproduce this, please report a new issue at https://github.com/SeleniumHQ/selenium/issues with reproduction steps. Exception message: TypeError: a.document.getElementsByTagName(...)[0].getButton is not a function
I have tried using driver.implicitly_wait(5)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable(DASHBOARD)).click()
print("Dashboard page clicked {}")
time.sleep(20)
driver.implicitly_wait(5)
It removes the warning but nothing much happens on the browser. The page still keeps on loading and nothing shows up.
How can I handle this behavior of the web page from python selenium. Please help. Thanks
I have a problem with loading the browser in selenium. I can run my driver.get() when I'm not using an extension. When I am using an extension it is freezing on the google chrome white screen and I NEED to press the refresh button on the top left corner in order to load the page that I want. The extension is also loaded in the google chrome right top corner and I dont get an error message. It isn't going to the page that I want. I have changed the url's also but nothing is changing. I have both chromedriver as google chrome version 74. Im closing all the google chrome tasks from taskmanager and run the program but still not working.
What I have:
options = Options()
options.add_extension(r"C:\Users\x\OneDrive\Desktop\crxSolver.crx")
driver = webdriver.Chrome(r'C:\Users\x\OneDrive\Desktop\chromedriver.exe', options=options)
driver.get("https://yahoo.com")
Displaying what is happening
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