UnexpectedAlertPresentException: Alert Text: error: Message: unexpected alert open: {Alert text : error:} Python - selenium

I am running a selenium script on EC2 amazon linux 2, which run well, but after many hours of it doing it's job, I get the following error:
selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: error:
Message: unexpected alert open: {Alert text : error:}
(Session info: headless chrome=103.0.5060.114)
I am using ChromeDriverManager
How can I know why it fail after long time of running well?

Related

Selenium error: Chrome failed to start: exited abnormally. (unknown error: DevToolsActivePort file doesn't exist)

options = Options()
options.add_argument('use-fake-device-for-media-stream')
options.BinaryLocation = "/usr/bin/chromium-browser"
driver = webdriver.Chrome(executable_path="/usr/bin/chromedriver",options=options)
On executing the above with sudo python3 script_name.py, the following errows shows up:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /snap/chromium/current/command-chromium.wrapper is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
The above error doesnt show up on executing python3 script_name.py, I believe that has to do something with the display.
Please let me know how I can resolve this.
Other details:
Chromium version: 85.0.4183.83
Selenium version:3.141.0
Chrome webDriver version: 85.0.4183.83

use normal browser profile as selenium profile

my os is Ubuntu 16.04, the default chrome profile is in :
~/.config/google-chrome
so i setup my selenium option with :
options.add_argument("--user-data-dir=/home/user/.config/google-chrome")
but no luck, the error message :
Message: unknown error: Chrome failed to start: exited abnormally

Selenium in Jenkins failure test

I'm trying to run selenium in Jenkins. When I run it locally the test always passed. But in Jenkins I always get error:
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator#ee7d9f1
Starting ChromeDriver 2.34.522932 (4140ab217e1ca1bec0c4b4d1b148f3361eb3a03e) on port 10010
Only local connections are allowed.
Dec 18, 2017 2:35:43 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
File cannot be found
Tests run: 4, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 6.807 sec <<< FAILURE!
no such element: Unable to locate element:
Im using Jenkins, Selenium and Testing
This issue is related to your mac, and is a connection issue to other server on which you are running your script. for resolving this issue please read this: https://discussions.apple.com/thread/1789752

Appium crashes giving the error "Error getting source, can't continue finding element by XPath"

My appium version is 1.4.13. Xcode version is 7, iOS simulator version is 8.4.
Appium server crashes while trying to execute a command.
The same test used to work perfectly fine. Not sure why it is not working now.
I have also added the following command in my capabilities.
capabilities.setCapability("newCommandTimeout" , 60);
Appium log is pasted here.
info: [IOS_SYSLOG_ROW ] Jan 13 16:17:37 clones-MacBook-Pro-6.local DTMobileIS[7664]: Could not create service named com.apple.instruments.server.services.processcontrol.posixspawn
info: [debug] Cleaning sim data files
info: node-simctl: Executing: xcrun with args: simctl erase 3C31DBE5-A0FD-4C5A-BAEC-C02DF76BFB36 and timeout: 2000
error: Error getting source, can't continue finding element by XPath
info: [debug] Cleaning app data files
warn: Applications directory /Users/Bindu/Library/Developer/CoreSimulator/Devices/3C31DBE5-A0FD-4C5A-BAEC-C02DF76BFB36/data/Containers/Data/Application doesn't exist. Have you run this simulator before?
warn: Applications directory /Users/Bindu/Library/Developer/CoreSimulator/Devices/3C31DBE5-A0FD-4C5A-BAEC-C02DF76BFB36/data/Containers/Bundle/Application doesn't exist. Have you run this simulator before?
info: Couldn't find app directories to delete. Probably it's not installed
info: [debug] We were in the middle of processing a command when instruments died; responding with a generic error
info: [debug] Cleaning up appium session
info: [debug] Condition unmet after 2355ms. Timing out.
info: [debug] Responding to client with error: {"status":13,"value":{"message":"Instruments died while responding to command, please check appium logs","name":"UnknownError","origValue":"Instruments died while responding to command, please check appium logs"},"sessionId":null}
info: <-- POST /wd/hub/session/07d24536-708f-4515-af69-a35d5695119e/element 500 2356.834 ms
Here is the code for running my tests:
public void completeSignUpForm() throws InterruptedException {
elementUtils.sendValueToElement(FIRSTNAME, "TestName");
elementUtils.sendValueToElement(LASTNAME, "TestSurname");
elementUtils.sendValueToElement(PASSWORD, "Drayson123");
elementUtils.clickElementByXpath(AGE);
elementUtils.enterDataIntoPickerWheel(AGE_PICKER_WHEEL, "26-35", 0);
elementUtils.clickElementByXpath(PICKER_WHEEL_DONE_BUTTON);
elementUtils.clickElementByXpath(GENDER);
elementUtils.enterDataIntoPickerWheel(GENDER_PICKER_WHEEL, "Female", 0);
elementUtils.clickElementByXpath(PICKER_WHEEL_DONE_BUTTON);
elementUtils.clickElementByXpath("//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[9]/UIASwitch[1]");
Thread.sleep(3000);
elementUtils.clickElementByXpath(JOIN_US_BUTTON);
}
Support code for the methods from ElementUtils class are below:
public void sendValueToElement(String xpathSelector, String inputvalue) {
MobileElement element = (MobileElement) driver.findElementByXPath(xpathSelector);
element.setValue(inputvalue);
}
public void clickElementByXpath(String XpathSelector) {
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(XpathSelector)));
driver.findElement(By.xpath(XpathSelector)).click();
}
public void enterDataIntoPickerWheel(String xpathSelector, String text, int index) {
waitForElement(By.xpath(xpathSelector));
List<WebElement> we = driver.findElements(By.xpath(xpathSelector));
we.get(index).sendKeys(text);
}
Is the app working well without Appium in place. I meant install the App in Simulator and launch it and check if the app works fine.
If you see any issue then you have to fix it at that level. otherwise can you add full appium log.
To do so , you can do like below Link
To get the list of Simulators available in your system , you can type below command.Open Terminal and type below command
$ xcrun instruments -s
To launch Simulator using command line , you can type below command and provide same of simulator as you got from step 1 above
$ xcrun instruments -w "iPhone 6 (9.2)” // replace with your Simulator name
To install app on Simulator using command line once Simulator is up and running, you can type below command
$ xcrun simctl install booted <app path>
e.g.
$ xcrun simctl install booted /Users/macuser/Desktop/UIKitCatalog.app

Protractor redirects and times out immediately after loading page

I'm trying to write some e2e specs for an AngularJS application. I have one Jasmine spec in test/e2e/test_spec.js:
describe('basic functionality', function() {
it('loads the home page', function() {
browser.get('/');
expect(browser.getCurrentUrl()).toMatch(/localhost/);
});
});
Terminal output when the spec is run:
> protractor protractor.config.js
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
basic functionality
loads the home page - fail
Failures:
1) basic functionality loads the home page
Message:
Error: waiting for page to load for 10000ms
Wait timed out after 10013ms
Stacktrace:
Error: waiting for page to load for 10000ms
Wait timed out after 10013ms
at Array.forEach (native)
From: Task: waiting for page to load for 10000ms
at [object Object].<anonymous> (/Users/jdent/swamp-bunny/test/e2e/test_spec.js:3:13)
From: Task: Asynchronous test function: it()
Error
at [object Object].<anonymous> (/Users/jdent/swamp-bunny/test/e2e/test_spec.js:2:3)
at Object.<anonymous> (/Users/jdent/swamp-bunny/test/e2e/test_spec.js:1:63)
Finished in 10.955 seconds
1 test, 1 assertion, 1 failure
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1
While the console is sitting on [launcher] Running 1 instances of WebDriver, Chrome opens and displays the index page for a fraction of a second, then changes to a blank page with data:text/html,<html></html> in the address bar.
Here is my protractor.config.js:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'chrome'
},
specs: 'test/e2e/**/*_spec.js',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
isVerbose: true
},
allScriptsTimeout: 20000,
onPrepare: function() {
return browser.driver.get("http://localhost:8100");
}
};
My webdriver-manager stuff seems to be up to date, although the tool doesn't seem to have a way to output version numbers.
> webdriver-manager status
selenium standalone is up to date
chromedriver is up to date
IEDriver is not present
Why is the spec failing?
Edit: This is what is printed to the terminal when onPrepare is commented out:
> protractor protractor.config.js
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
A Jasmine spec timed out. Resetting the WebDriver Control Flow.
The last active task was:
unknown
basic functionality
loads the home page - fail
Failures:
1) basic functionality loads the home page
Message:
timeout: timed out after 30000 msec waiting for spec to complete
Stacktrace:
undefined
Finished in 34.27 seconds
1 test, 1 assertion, 1 failure
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1
Edit 2: When I do browser.get("http://google.com"), Chrome briefly shows the data: and data:text/html,<html></html> pages, redirects to Google, then times out looking for Angular.
> protractor protractor.config.js
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
basic functionality
loads the home page - fail
Failures:
1) basic functionality loads the home page
Message:
Error: Angular could not be found on the page http://google.com/ : retries looking for angular exceeded
Stacktrace:
Error: Angular could not be found on the page http://google.com/ : retries looking for angular exceeded
at Array.forEach (native)
From: Task: Asynchronous test function: it()
Error
at [object Object].<anonymous> (/Users/jdent/swamp-bunny/test/e2e/test_spec.js:2:3)
at Object.<anonymous> (/Users/jdent/swamp-bunny/test/e2e/test_spec.js:1:63)
Finished in 12.186 seconds
1 test, 1 assertion, 1 failure
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1
Set baseUrl: 'http://localhost:8100' in your protractor.config.js file. From the Protractor Reference Config:
A base URL for your application under test. Calls to protractor.get() with relative paths will be prepended with this.
It is a sporadic open bug in protractor https://github.com/angular/protractor/issues/5103
Instead of this
browser.get('http://juliemr.github.io/protractor-demo/');
Using this has solved my issue.
browser.driver.get('http://juliemr.github.io/protractor-demo/');
I had that problem in chrome. I read somewhere that protractor starts on that data:text/html,<html></html> page. Calling browser.get(...) navigates away from that page. My idea was to open chrome already on my base url. I accomplished that by adding it to the capabilities like this:
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'args': ['--app=www.yourBaseUrl.com']
}
},
It's a bit of a hack, but it seems to have done the trick.