How to remove unresponsive script in Firefox with selenium python - python

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

Related

How to catch console log of an iframe with Python, Selenium and Chrome?

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

Selenium browser not loading python with extension

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

Selenium Web driver is not able to find the div class in Google Chrome webstore

I want to crawl some data from Google Chrome Website. But I am facing a problem whenever trying to use selenium webdriver. When I use following code I get an error stating that this element doesn't exist in the site.
button = driver.find_element_by_class_name("a-d-l-L")
Snapshot of the website:
And also, how to get data from a pop up window (this window comes up when I press a button). Following screen can be found on the next page. I want to store the data that is showing in the pop up message.
Google has special permissions on the Chrome Webstore, as of now you can't use Selenium to automate any page on the Chrome Webstore website.

Upload file by sendkeys in python opens a file selector popup

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.

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

Categories

Resources