I have the error when run selenium on local machine which is Windows 10 Enterpise 64-bit (Microsoft Edge Version: 25.10586.672.0)and Microsoft WebDriver - Release 10240. My Selenium version is: 3.6.0
public class SeleniumTest {
private WebDriver driver;
#BeforeClass
public void getWebDriver() {
try {
System.setProperty("webdriver.edge.driver", "myapp/driver/MicrosoftWebDriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.edge();
capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
capabilities.setCapability(CapabilityType.PAGE_LOAD_STRATEGY, "eager");
capabilities.setPlatform(Platform.WIN10);
capabilities.setBrowserName(BrowserType.EDGE);
capabilities.setVersion("");
driver = new EdgeDriver(capabilities);
} catch (Exception e) {
e.printStackTrace();
}
driver.get(Constant.URL);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
}
#AfterClass
public void quitDriver() throws InterruptedException {
Thread.sleep(3000);
driver.quit();
}
#Test ()
public void aTest() {
}
#Test ()
public void bTest() {
}
}
When I run code it open the Edge Browser and has error:
org.openqa.selenium.NoSuchSessionException: null (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 873 milliseconds
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
System info: host: 'computername', ip: 'myip', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_111'
Driver info: driver.version: EdgeDriver
You may consider to look into the Release Notes as it mentions:
Updating .NET bindings to not send incorrect W3C Firefox capabilities
Previously, RemoteWebDriver would send the same capabilities dictionary
using both the "desiredCapabilities" and "capabilities" properties when
requesting a new remote session. In the case of the language bindings
expressly requesting to use the legacy Firefox driver, the capabilities
dictionary will include properties that are invalid for the W3C-compliant
remote server. To resolve that issue, we will mask the explicit attempt by
setting a property that causes the .NET RemoteWebDriver to send a
legacy-only compatible new session request when explicitly requesting the
legacy driver.
I don't see any significant error as such in your code except one, to see NoSuchSessionException. Instead of:
DesiredCapabilities capabilities = DesiredCapabilities.edge();
You should use:
DesiredCapabilities cap = new DesiredCapabilities();
It's possible you also need to start a driver service, i.e.
service = new EdgeDriverService.Builder()
.usingDriverExecutable(new File("path/to/my/MicrosoftWebDriver.exe"))
.usingAnyFreePort()
.build();
service.start();
Have a look at this example of an EdgeDriver.
Related
whenever my code is executing it is getting navigating to some other page. My code is of how to handle with calendar in selenium.
please help
package basic;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class calender {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new ChromeDriver();
//Launching website
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.get("https://www.path2usa.com/travel-companions");
//selecting dates
driver.findElement(By.xpath("//*[#id=\"travel_date\"]")).click();
while(!driver.findElement(By.cssSelector("[class='datepicker-days'] th[class='datepicker-switch']")).getText().contains("April"))
{
driver.findElement(By.cssSelector("[class='datepicker-days'] th[class='next']")).click();
}
List<WebElement> dates = driver.findElements(By.className("day"));
//grab common attribute // put into list and iterate
int count = driver.findElements(By.className("day")).size();
for(int i=0;i<count;i++)
{
String text = driver.findElements(By.className("day")).get(i).getText();
if(text.equalsIgnoreCase("23"))
{
driver.findElements(By.className("day")).get(i).click();
break;
}
}
}
}
starting ChromeDriver 73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72) on port 13761
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Apr 01, 2019 9:38:18 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Cannot locate an element using css selector=[class='datepicker-days'] th[class='datepicker-switch']
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'Nilufars-MacBook-Air.local', ip: '2405:204:4383:7327:1104:ad36:576:9d64%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_201'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:327)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByCssSelector(RemoteWebDriver.java:420)
at org.openqa.selenium.By$ByCssSelector.findElement(By.java:431)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
at basic.calender.main(calender.java:23)
Welcome to SO.
You can directly select the date as shown below.
driver.findElement(By.xpath("//input[#name='travel_date']")).sendKeys("25 May 2019");
This way you will save your execution time by ignoring the month loop and date loop.
Simplified code:
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.get("https://www.path2usa.com/travel-companions");
//selecting the date
driver.findElement(By.xpath("//input[#name='travel_date']")).sendKeys("25 May 2020");
//continue your test with next steps
// quit the driver.
driver.quit();
My Emulator android phone has android default browser, when appium test the android default browser, it can't take screenshot on failure using TakesScreenshot.How can I to solve it.
I am using Selenium Remote Webdriver as driver instance
public synchronized static void captureScreenshot(WebDriver driver, String screenshotName) {
try {
TakesScreenshot ts = (TakesScreenshot) driver;
File source = ts.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(source, new File("./Screenshots/"
+ screenshotName + ".png"));
System.out.println("Screenshot taken");
filePath=timestamp()+ screenshotName + ".png";
} catch (Exception e) {
System.out.println("Exception while taking screenshot "
+ e.getMessage());
}
}
CONSOLE LOGS :
Exception while taking screenshot An unknown server-side error occurred while processing the command. Original error: Could not proxy. Proxy error: New Command Timeout of 60 seconds expired. Try customizing the timeout using the 'newCommandTimeout' desired capability (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 660.36 seconds
Build info: version: '2.44.0', revision: '76d78cf323ce037c5f92db6c1bba601c2ac43ad8', time: '2014-10-23 13:11:40'
System info: host: 'DocASAP-mac-mini.local', ip: '192.168.1.45', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.5', java.version: '1.7.0_79'
Session ID: f8bcc2d5-a00d-43c5-8a8a-157d2fbe6260
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{platform=ANDROID, javascriptEnabled=true, acceptSslCerts=true, browserName=Browser, networkConnectionEnabled=true, desired={newCommandTimeout=60, platform=ANDROID, autoAcceptAlerts=true, acceptSslCerts=true, deviceName=192.168.56.101:5555, platformName=Android, browserName=Browser, setAcceptUntrustedCertificates=true, version=5.1.0}, locationContextEnabled=false, deviceUDID=192.168.57.101:5555, version=5.1.0, newCommandTimeout=60, platformVersion=5.1, autoAcceptAlerts=true, databaseEnabled=false, deviceName=192.168.57.101:5555, platformName=Android, webStorageEnabled=false, setAcceptUntrustedCertificates=true, warnings={}, takesScreenshot=true}]
I am unable to run the basic selenium script which contains the HtmlUnitDriver. If I try to run the code I get the following error.
Code:
public class SampleUnitDriver
{
public static void main(String[] args) throws Exception
{
HtmlUnitDriver unitDriver = new HtmlUnitDriver();
unitDriver.get("http://google.com");
System.out.println("Title of the page is -> " + unitDriver.getTitle());
Thread.sleep(3000L);
WebElement searchBox = unitDriver.findElement(By.className("gsfi"));
searchBox.sendKeys("Selenium");
WebElement button = unitDriver.findElement(By.name("gbqfba"));
button.click();
System.out.println("Title of the page is -> " + unitDriver.getTitle());
}
}
Error:
Title of the page is -> Google
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Returned node was not a DOM element
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'user-PC', ip: '192.168.1.52', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_51'
Driver info: driver.version: SampleUnitDriver
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByCssSelector(HtmlUnitDriver.java:1060)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByClassName(HtmlUnitDriver.java:1032)
at org.openqa.selenium.By$ByClassName.findElement(By.java:391)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1725)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1721)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUnitDriver.java:1367)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:1721)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:606)
at com.digitalmqc.automation.action.SampleUnitDriver.main(SampleUnitDriver.java:16)
The class name gsfi of the input box is generated by javascript so you have 2 options:
Easy One: Just select it by using the id lst-ib
Better One: Wait for the element to be fully interactive. The reason behind this one being better is that you are trying to input text into the box which javascript plays a role. The former option may throw some unexpected errors.
Following tests is automated by using java and selenium-server-standalone-2.20.0.jar.
The test crashes with the error:
Page title is: cheese! - Google Search
Starting browserTest
2922 [main] INFO org.apache.http.impl.client.DefaultHttpClient - I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond
2922 [main] INFO org.apache.http.impl.client.DefaultHttpClient - Retrying request
Exception in thread "main" org.openqa.selenium.UnhandledAlertException: Modal dialog present (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.20 seconds
Build info: version: '2.20.0', revision: '16008', time: '2012-02-27 19:03:04'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_24'
Driver info: driver.version: InternetExplorerDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:170)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:129)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:438)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:139)
at org.openqa.selenium.ie.InternetExplorerDriver.setup(InternetExplorerDriver.java:91)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:48)
at com.pwc.test.java.InternetExplorer7.browserTest(InternetExplorer7.java:34)
at com.pwc.test.java.InternetExplorer7.main(InternetExplorer7.java:27)
Test Class:
package com.pwc.test.java;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import com.thoughtworks.selenium.Selenium;
public class InternetExplorer7 {
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver webDriver = new HtmlUnitDriver();
webDriver.get("http://www.google.com");
WebElement webElement = webDriver.findElement(By.name("q"));
webElement.sendKeys("cheese!");
webElement.submit();
System.out.println("Page title is: "+webDriver.getTitle());
browserTest();
}
public static void browserTest() {
System.out.println("Starting browserTest");
String baseURL = "http://www.mail.yahoo.com";
WebDriver driver = new InternetExplorerDriver();
driver.get(baseURL);
Selenium selenium = new WebDriverBackedSelenium(driver, baseURL);
selenium.windowMaximize();
WebElement username = driver.findElement(By.id("username"));
WebElement password = driver.findElement(By.id("passwd"));
WebElement signInButton = driver.findElement(By.id(".save"));
username.sendKeys("myusername");
password.sendKeys("magic");
signInButton.click();
driver.close();
}
}
I don't see any modal dialog when I launched the IE7/8 browser manually. What could be causing this?
You may take a screenshot by webDriver to see the modal dialog when this Exception occurs.
I was also getting the same exception on Firefox. I observed that the username and password fields were autocompleted because the option "Remember passwords for sites" was enabled in Firefox. So, while recording even if I erase the contents and enter, it would not record the data entered. I disabled the option and rerecorded my test case. Now, it works fine.
Hope it helps.
I'm using the 2.4.0 selenium server in hub mode with two nodes each with 5 instances of Internet explorer (IE8 on win7) - this is all running on the same Win7 machine
The following code throws the exception on the final call to FindElements on the RemoteWebDriver
_driver.Navigate().GoToUrl(#"http://devrsql714/webpages/parentview.aspx");
var wait = new WebDriverWait(_driver, new TimeSpan(0, 0, 40));
wait.Until(d => d.FindElement(By.ClassName("TitleAlternative")));
Console.WriteLine(string.Format("Window title: {0}", _driver.Title));
var element = _driver.FindElementById("txtLessonID");
element.SendKeys("13814");
var button = _driver.FindElementById("btnLessonID");
button.Click();
wait = new WebDriverWait(_driver, new TimeSpan(0, 0, 40));
var link = wait.Until(d => d.Title.Contains("01652-06-A"));
Console.WriteLine(string.Format("Window title: {0}", _driver.Title));
Assert.IsTrue(_driver.Title.Contains("01652"));
Console.WriteLine(string.Format("page source: {0}", _driver.PageSource));
_driver.FindElementsByTagName("DIV");
I can see the browser load, navigate, fillin the text box and click the button - the page refreshes the title changes - the assert passes (this is running in MbUnit with Gallio)
but the subsequent call to _driver.FindElementsByTagName throws the exception below - I added waits in case that was the issue and any find elements results in the same exception
what am I doing wrong? - other properties on the driver work such as title and page source (which has the excepted content)
Note the same code but swapping the RemoteWebDriver for a local InternetExplorerDriver does not throw the exception
In both cases capabilities were set to ignore protect mode:
DesiredCapabilities capabilities = DesiredCapabilities.InternetExplorer();
capabilities.Platform = new Platform(PlatformType.Any);
capabilities.SetCapability("ignoreProtectedModeSettings", true);
Execute
OpenQA.Selenium.StaleElementReferenceException: Element specified by 'id' is no longer valid (WARNING: The server did not provide any stacktrace information)
Build info: version: '2.4.0', revision: '13337', time: '2011-08-12 09:57:13'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_20'
Driver info: driver.version: RemoteWebDriver
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 948
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(DriverCommand driverCommandToExecute, Dictionary`2 parameters) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 805
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElements(String mechanism, String value) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 851
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementsByTagName(String tagName) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 622
at SeleniumTests.DemoTest.AnotherTest()
This is apparently a bug in version 2.4.0 of the selenium server. Downgrading to 2.3.0 might make the problem go away. See this thread on the selenium-users mailing list for more information.