protractor NoSuchElementError: no such element - selenium

When I was try to send keys in non-angular page with protractor it shows an error "NoSuchElementError: no such element"
NoSuchElementError: no such element
(Session info: chrome=47.0.2526.80)
(Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 24 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'Sekhar-PC', ip: '192.168.1.3', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_13'
* Element info: {Using=id, value=ius-userids}
Session ID: 352e36f285f80dee03eb5c88697ebc08
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=C:\Users\Sekhar\AppData\Local\Temp\scoped_dir3128_18281}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=47.0.2526.80, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, applicationCacheEnabled=false, takesScreenshot=true}]
**

When testing non-Angular pages with Protractor, you need to include this line in all of your specs:
browser.ignoreSynchronization = true;
You also need to wait for the page to completely load. Using ExpectedConditions is one way to do that. Example:
var EC = protractor.ExpectedConditions;
browser.wait(EC.elementToBeClickable(element(by.css('.wait-for-me'))), 10000);

Use sleep condition.
browser.driver.sleep(500);
This will wait the browser for sometime.

Looks like timing issue, write some "expect" statements so that it will verify for particular functionality is available.
Try to use implicit wait.
Try writing your script in promises so that it will wait.
field.sendKeys(value).then(function(){
submitButton.click().then(function(){
expect('xyz').toBe(xyz);
});
});

Related

An unknown server-side error occurred while processing the command in Safari.

Having this error while trying to set the value of the textbox to blank in Safari 10.1.
Using WebdriverIO: 4.6.2
Scenario: Got a text already in the textbox. Have to make that textbox blank to reset the search.
Code Snippet:
$(elementSelector).setValue('');
browser.waitUntil(() =>{
//Some conditions to meet after reset
});
Error:
An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 11 milliseconds
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700'
System info: host: 'mac-185-44-130-79.browserstack.com', ip: '185.44.130.79', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.5', java.version: '1.8.0_51'
Driver info: org.openqa.selenium.safari.SafariDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, databaseEnabled=true, handlesAlerts=true, version=12604.1.22, cleanSession=true, platform=MAC, nativeEvents=true, locationContextEnabled=false, webStorageEnabled=true, browserName=safari, javascriptEnabled=true, platformName=macOS, cssSelectorsEnabled=true}]
Session ID: 89FDFB29-FF29-4DE0-B7D2-709AA0E86726

Selenium: How to click on href link when it wont have absolute path

I am trying to identify a link in the CQ5 webpage and click on it.
Below is the html code:
<a href="/siteadmin" title="Websites">
<div class="icon siteadmin">
<div class="title">Websites</div>
<div class="description">Create and manage multiple websites.
</div>
</div>
</a>
The below are method i tried to find the information and click on it.
driver.findElement(By.linkText("Websites")).click();
driver.findElement(By.xpath("//a[#href='/siteadmin']")).click();
Getting following exception:
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (528, 174). Other element would receive the click: <div class="resourcebox">...</div>
(Session info: chrome=52.0.2743.116)
(Driver info: chromedriver=2.22.397933 (1cab651507b88dec79b2b2a22d1943c01833cc1b),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 39 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:32:46'
System info: host: 'pilapwin7020', ip: '10.116.252.187', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_101'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.22.397933 (1cab651507b88dec79b2b2a22d1943c01833cc1b), userDataDir=C:\Users\User\AppData\Local\Temp\scoped_dir44444_30971}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=52.0.2743.116, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 5116ba44126c39293ac466aed3d6608a
You should try using JavascriptExecutor to perform click in this case as :-
((JavascriptExecutor)driver).executeScript("arguments[0].click()", driver.findElement(By.cssSelector("a[href = '/siteadmin'][title = 'Websites']")));
You need to check if the attr contains the string, because it returns the fullpath even if in the HTML shows only /siteadmin.
XPath Solution:
//a[contains(#href, '/siteadmin') and #title='Websites']
Css Selector Solution:
a[href*='/siteadmin'][title='Websites']

How to use Alert box on button click in selenium by using web driver in java [duplicate]

This question already has answers here:
Alert handling in Selenium WebDriver (selenium 2) with Java
(5 answers)
Closed 6 years ago.
Please help me Tester, i am frustrated this point i have apply more and more code but no solution found again and same message show.
................................................................................
org.openqa.selenium.UnhandledAlertException: Unexpected modal dialog (text: Meal Added to Shopping List): Meal Added to Shopping List
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'Saurabh', ip: '192.168.3.21', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=46.0.1, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 87eb9958-85a9-4571-8bbd-663fdaad2ad0
You can try this:
WebDriverWait wait = new WebDriverWait(driver, 3);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.accept();
Hope this helps!!

Selenium executeScript fails sometimes

i've created the following function to click elements
private WebDriverWait wait;
public void clickElement(By element) throws InterruptedException {
// wait element is clickable
wait.until(ExpectedConditions.presenceOfElementLocated(element));
// driver.findElement(element).click();
((JavascriptExecutor) driver).executeScript("arguments[0].click();", driver.findElement(element));
waitForAjaxLoadScreenDisappear();
}
we click thousands of elements, but sometimes randomly an error occurs:
arguments[0] is undefined Command duration or timeout: 223 milliseconds Build info: version: '2.45.0', revision: '5017cb8e7ca8e37638dc3091b2440b90a1d8686f', time: '2015-02-27 09:10:26' System info: host: 'linux-1au3', ip: '192.168.1.194', os.name: 'Linux', os.arch: 'amd64', os.version: '3.1.10-1.23.1-desktop', java.version: '1.7.0_21' Session ID: 471aca55-ae19-439e-aaa2-b2ba970a1252 Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, browserConnectionEnabled=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=20.0}]
How can arguments[0] be undefined, when the wait.until has finished?
usually buttons have enable/disable attributes, so along with asserting it's visible you also might want to check if they are clickable/enabled...
you should be able to do something like the below:
element.isEnabled()
Then you probably want to loop until it's true before interacting with the element...

WebDriverBackedSelenium in Internet Explorer is not working

An error can be seen while running the test in Selenium, I have tried removing and adding the capabilities but in vain:
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver driver = new InternetExplorerDriver(capabilities);
WebDriverBackedSelenium selenium = new WebDriverBackedSelenium(driver, url);
Thread.sleep(3000);
selenium.open(url);
driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
selenium.type("userId", "TEst");
The error is thrown because of the line selenium.type("userId", "TEst") and the error is as follows:
JavaScript error (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 81 milliseconds
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:18:15'
System info: host: 'slc05apo', ip: '10.241.115.70', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_26'
Session ID: 4368aa6a-ba4a-42a9-8428-1ce9a8f71dcc
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0, enablePersistentHover=true, ignoreZoomSetting=false, ie.ensureCleanSession=false, browserName=internet explorer, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss, version=8, ie.usePerProcessProxy=false, cssSelectorsEnabled=true, ignoreProtectedModeSettings=false, requireWindowFocus=false, handlesAlerts=true, initialBrowserUrl=http://localhost:39326/, ie.forceCreateProcessApi=false, nativeEvents=true, browserAttachTimeout=0, ie.browserCommandLineSwitches=, takesScreenshot=true}]
But no error can be seen if I use this:
WebDriver driver = new InternetExplorerDriver( DesiredCapabilities.internetExplorer());
driver.get(url);
driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
driver.findElement(By.id("userId")).sendKeys("test");
But I want to use the first given case. Please help.
Whatever the capabilities you are setting, should be passed when instantiating the driver.
Please change this
WebDriver driver = new InternetExplorerDriver( DesiredCapabilities.internetExplorer());
to
WebDriver driver = new InternetExplorerDriver(capabilities);
Hope this works.