Selenium HtmlUnit Driver Exception - java

I'm using JUnit, Selenium WebDriver and try to make some tests with HtmlUnit and http://vk.com site but fail.
It looks like FirefoxDriver works great for me.
Here is code:
#Before
public void setUp() {
DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
capabilities.setBrowserName("Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0");
capabilities.setVersion("24.0");
capabilities.setJavascriptEnabled(true);
driver = new HtmlUnitDriver(capabilities);
driver.manage().timeouts()
.implicitlyWait(Integer.parseInt(TIMEOUT), TimeUnit.SECONDS);
driver.get("http://vk.com");
}
#Test
public void SomeTest() {
/* LoginPage - described class in PageObject traditions */
LoginPage start = new LoginPage(driver);
LOG.info(driver.getPageSource());
//...
}
When I start it I get the an exception:
org.openqa.selenium.WebDriverException: com.gargoylesoftware.htmlunit.ScriptException: Exception invoking setInnerHTML
Build info: version: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:14:00'
System info: host: 'hera', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10-3-amd64', java.version: '1.6.0_27'
Driver info: driver.version: HtmlUnitDriver
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:484)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:463)
at vk.Execution.setUp(Execution.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
Any suggestions?
ps. This is black-box testing I've no access to change internal code on site.

Different drivers have different ways to handle javascript.
Htmlunit uses Rhino and firefox-driver uses Firefox's default javascript handler and hence, you see different results with different drivers.

Replace htmlUnit() with firefox() for your fix.
DesiredCapabilities capabilities = DesiredCapabilities.firefox()
capabilities.setBrowserName("Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0");
capabilities.setVersion("24.0");
driver = new HtmlUnitDriver(capabilities);

Related

Selenium : The browser is getting opened but not able to get URL in the browser

OS:Windows 10
Execution Environment : JavaSE-1.8 (jre1.8.0_144)
JARs and class folders on build path:
client-combined-3.6.0-sources.jar
client-combined3.6.0.jar
selenium-server-standalone-3.6.0.jar
Browser:
FireFox 56.0
Code Snippet:
System.setProperty("webdriver.firefox.marionette","C:/Users/admin/Downloads/geckodriver-v0.11.1-win32/geckodriver.exe");
WebDriver driver = new FirefoxDriver ();
driver.get("https://www.facebook.com");
Error:
Exception in thread "main" org.openqa.selenium.WebDriverException: Timed out waiting 45 seconds for Firefox to start.
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:26.402Z'
System info: host: 'ADMIN-PC', ip: '192.168.1.6', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_144'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.XpiDriverService.waitUntilAvailable(XpiDriverService.java:112)
at org.openqa.selenium.firefox.XpiDriverService.start(XpiDriverService.java:97)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:217)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:140)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:120)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:98)
at FacebookFriends.main(FacebookFriends.java:18)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:45149/hub/status] to be available after 45005 ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100)
at org.openqa.selenium.firefox.XpiDriverService.waitUntilAvailable(XpiDriverService.java:110)
... 8 more
Caused by: java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask.get(Unknown Source)
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:147)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75)
... 9 more
First of all You are using a little bit old version of gecko driver. The newest from: https://github.com/mozilla/geckodriver/releases
Then You need to set up system property with:
File gecko = new File("C:/Users/admin/Downloads/geckodriver-v0.19.0-win32/geckodriver.exe");
System.setProperty("webdriver.gecko.driver", gecko.getAbsolutePath());
If You really want to use marionette check answers on: Difference between webdriver.firefox.marionette & webdriver.gecko.driver
I haved this error for 2 days, the solution for me was in Set.Plataform put Platafor.ANY or Plataform.Windows because Plataform.WIN10 not worked, marionette wasn't necessary and I added and neether works, only works this. I hope this helps someone else:
public class Main {
public static RemoteWebDriver driver;
public static void main(String[] args) throws MalformedURLException {
System.setProperty("webdriver.gecko.driver", "D:/Lib/geckodriver.exe");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities().firefox();
desiredCapabilities.setPlatform(Platform.ANY);
desiredCapabilities.setBrowserName("firefox");
driver = new RemoteWebDriver(new URL("http://172.20.19.182:5557/wd/hub"), desiredCapabilities);
driver.navigate().to("http://www.google.com");
driver.findElementByName("q").sendKeys("execute automation");
driver.findElementByName("q").sendKeys(Keys.ENTER);
driver.close();
// write your code here
}
}
You can also try using double \\ in the path of the geckodriver.
Also instead of using :
System.setProperty(
"webdriver.firefox.marionette",
"C:/Users/admin/Downloads/geckodriver-v0.11.1-win32/geckodriver.exe");
Can you try using
System.setProperty(
"webdriver.gecko.driver",
"C:\\Users\\admin\\Downloads\\geckodriver-v0.11.1-win32\\geckodriver.exe");
Title : Problem Resolved
Solution Accepted :
- Use latest version of gecko driver
Code Used
- System.setProperty("webdriver.gecko.driver","C:\Marionette\geckodriver_1.exe" );

Appium Automation: Getting error - org.openqa.selenium.WebDriverException: Unable to parse remote response: Parameters were incorrect

I am trying to do appium android automation using Java. Below is the code:
public class Main {
AppiumDriver driver;
#Before
public void setup() throws Exception{
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("platformVersion","4.4");
desiredCapabilities.setCapability("platformName","Android");
desiredCapabilities.setCapability("app","/PATH_TO_APK");
driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"),desiredCapabilities);
}
#After
public void tearDown(){
driver.quit();
}
#Test
public void firstTest(){
WebElement element = driver.findElementById("ELEMENT_ID");
element.click();
}
}
Below is the error
org.openqa.selenium.WebDriverException: Unable to parse remote response: Parameters were incorrect. We wanted {"required":["desiredCapabilities"],"optional":["requiredCapabilities","sessionId","id","sessionId","id","sessionId","id","sessionId","id","sessionId","id","sessionId","id"]} and you sent ["desiredCapabilities","requiredCapabilities","capabilities"]
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'WGB01ML106163.local', ip: 'fe80:0:0:0:3e15:c2ff:febe:8ea0%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_131'
Driver info: driver.version: AndroidDriver
Has anyone seen this error before? Cant find anything on Google. Please help.
We also need to pass the "deviceName" in the capabilities.
desiredCapabilities.setCapability("deviceName","Android");
Also, if you doing hybrid/native app testing in the mobile, we need to pass appPackage and appActivity also. So combining all the mandatory capabilities, overall desired capabilities will look similar to this.
public void setup() throws Exception
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","ANDROID");
capabilities.setCapability("platformVersion", "5.1");
capabilities.setCapability("platformName",Constant.appPlatform);
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", Constant.appPackage);
capabilities.setCapability("appActivity",Constant.appActivity);
driver = new AndroidDriver(new URL("http://127.0.0.1:4727/wd/hub"),capabilities);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}
Easy way to get appActivity/appPackage is contacting your developer. If not possible check this=>appActivity/appPackage
More details about various capabilities are available here.
https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md

WebElement#getScreenShotAs(OutputType.File) not working

I am trying to use WebElement#getScreenShotAs(OutputType.FILE) feature added in selenium webdriver 2.47.0 version on Firefox Browser
Code
public static void main(String[] args) throws IOException {
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://automationpractice.com/index.php");
WebElement element=driver.findElement(By.cssSelector("a[title='Contact Us']"));
System.out.println(element.getText());
element.getScreenshotAs(OutputType.FILE);
File destination=new File("Image.png");
FileUtils.copyFile(null, destination);
}
..But I am getting below exception:
Contact us
Exception in thread "main" org.openqa.selenium.UnsupportedCommandException: Unrecognized command: GET /session/e796089b-1d64-4590-9157-a0716a57e399/screenshot/%7B4329461b-5e9c-4f8b-b589-ddc1af1d55a6%7D
Command duration or timeout: 16 milliseconds
Build info: version: '2.52.0', revision: '4c2593cfc3689a7fcd7be52549167e5ccc93ad28', time: '2016-02-11 11:22:43'
System info: host: 'mrunal-laptop', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_45'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=41.0.2, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: e796089b-1d64-4590-9157-a0716a57e399
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:327)
at org.openqa.selenium.remote.RemoteWebElement.getScreenshotAs(RemoteWebElement.java:447)
at thirdsession.GetProperties.main(GetProperties.java:20)
The real reason for the error is that many / most WebDriver implementations do not actually support element-based screenshots, despite WebElement extending TakesScreenshot since 2.47.0. Perhaps someday this will change.
If you want screenshots you need to do them at the whole-browser level, in which case - as other answers have it - you need to pass the WebDriver instance.
File ssFile = ((TakesScreenshot)(driver)).getScreenshotAs(OutputType.FILE);
Strictly speaking you should probably do the following, since not all Drivers are guaranteed to support screenshots, e.g. HtmlUnitDriver.
if (!(getDriver() instanceof TakesScreenshot)) {
File ssFile = ((TakesScreenshot)(driver)).getScreenshotAs(OutputType.FILE);
// ...
}
There are alternate solutions for single-element screenshots, but they inevitably involve cropping of the full-browser screenshot. See, for example: https://stackoverflow.com/a/13834607/954442
Update: just to clarify that this is not a bug, it's that although element screenshots are a part of the W3C WebDriver spec, different browsers have different levels of compliance/coverage, and as far as I know this feature is only supported by Microsoft Edge.
Dont Import these lib from Suggestions,
import org.eclipse.jetty.server.Response.OutputType;
import org.seleniumhq.jetty9.server.Response.OutputType;
Import these lib.
import org.openqa.selenium.OutputType;
It should be something like this.
File screenS = ((TakesScreenshot)(driver)).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenS, new File("C:\\akshay\\del\\screenshots\\1.jpg"));
replace the above code with
element.getScreenshotAs(OutputType.FILE);
File destination=new File("Image.png");
FileUtils.copyFile(null, destination);
The getScreenShotAs() method is not defined as part of the WebElement interface. Rather, it is included as part of the TakesScreenshot interface. If you want to take a screenshot and save it to a file, try the following:
File file = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

driver.get not working in Selenium Webdriver, Java

When using driver.get on a certain website (driver.get("http://steamcommunity.com/market/search?appid=730")), I get this error:
Exception in thread "main" org.openqa.selenium.WebDriverException: com.gargoylesoftware.htmlunit.ScriptException: Exception invoking fireEvent
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'daltonpc', ip: '10.0.0.2', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_45'
Driver info: driver.version: HtmlUnitDriver
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:504)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:480)
at org.openqa.selenium.example.FinderClass.findOtherWeapon(FinderClass.java:60)
at org.openqa.selenium.example.Main.main(Main.java:20)
Caused by: com.gargoylesoftware.htmlunit.ScriptException: Exception invoking fireEvent
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:705)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:637)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:612)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:1001)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventListeners(EventListenersContainer.java:179)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:239)
at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:824)
at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:748)
at com.gargoylesoftware.htmlunit.html.HtmlElement$1.run(HtmlElement.java:920)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:925)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1298)
at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:290)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:475)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:342)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:407)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:491)
... 3 more
Caused by: java.lang.RuntimeException: Exception invoking fireEvent
at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:148)
at net.sourceforge.htmlunit.corejs.javascript.FunctionObject.call(FunctionObject.java:448)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1531)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:411)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:309)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3057)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:103)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:630)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:690)
... 22 more
Caused by: com.gargoylesoftware.htmlunit.ScriptException: illegal radix 0. (http://steamcommunity-a.akamaihd.net/public/shared/javascript/shared_global.js?v=BESEFoKTgss6&l=english#1358)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:705)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:637)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:612)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:1001)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventListeners(EventListenersContainer.java:179)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:239)
at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:814)
at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:748)
at com.gargoylesoftware.htmlunit.javascript.host.EventNode.fireEvent(EventNode.java:396)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:120)
... 32 more
Caused by: net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: illegal radix 0. (http://steamcommunity-a.akamaihd.net/public/shared/javascript/shared_global.js?v=BESEFoKTgss6&l=english#1358)
at com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter.runtimeError(StrictErrorReporter.java:81)
at net.sourceforge.htmlunit.corejs.javascript.Context.reportRuntimeError(Context.java:1047)
at net.sourceforge.htmlunit.corejs.javascript.Context.reportRuntimeError(Context.java:1094)
at net.sourceforge.htmlunit.corejs.javascript.Context.reportRuntimeError1(Context.java:1062)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.numberToString(ScriptRuntime.java:813)
at net.sourceforge.htmlunit.corejs.javascript.NativeNumber.execIdCall(NativeNumber.java:129)
at net.sourceforge.htmlunit.corejs.javascript.IdFunctionObject.call(IdFunctionObject.java:89)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1531)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:630)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:690)
... 47 more
It works fine with other urls, and it also worked with this one until I enabled javascript by putting true in WebDriver driver = new HtmlUnitDriver(true);. I needed to do this because my program wasn't working properly without javascript, and it seems like this steam community market page requires javascript in order to access it, even by just typing in the url. What am I doing wrong?
Using a user agent will solve the ScriptException. Use DesiredCapabilties to do so. See below code:
DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
capabilities.setBrowserName("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20160101 Firefox/66.0");
HtmlUnitDriver driver = new HtmlUnitDriver(capabilities);
driver.setJavascriptEnabled(true);
driver.get("http://steamcommunity.com/market/search?appid=730");
System.out.println(driver.getPageSource());
This works fine.
Although, an alternate solution would be to use PhantomJSDriver which I found to be much better at locating elements.
Download PhantomJS.exe file and set the exe's file path as PHANTOMJS_EXECUTABLE_PATH_PROPERTY
public class CopyOfTest1
{
PhantomJSDriver driver;
WebDriverWait wait;
DesiredCapabilities capabilities;
CopyOfTest1()
{
//set binary path of phantomJS driver
capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "drivers/phantomjs.exe");
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX,"Y");
capabilities.setCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:16.0) Gecko/20121026 Firefox/16.0");
//intialize driver and set capabilties
driver = new PhantomJSDriver(capabilities);
//intitlaize webdriverwait class
wait = new WebDriverWait(driver, 30);
}
void start()
{
driver.get("http://steamcommunity.com/market/search?appid=730");
System.out.println(driver.getPageSource());
driver.quit();
}
public static void main(String[] args) throws Exception
{
new CopyOfTest1().start();
}
}
You are missing double quotation " in url. Try the following
driver.get("http://steamcommunity.com/market/search?appid=730")

org.openqa.selenium.NoSuchElementException: Unable to locate element:

Code:
public void Test2() throws Exception{
Thread.sleep(5000);
driver.findElement(By.id("cboMenu")).click();
driver.findElement(By.xpath(".//*[#id='cboMenu/option[3]")).click();
}
Error:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"cboMenu"}
Command duration or timeout: 31 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'
System info: host: 'venu-PC', ip: '192.168.1.3', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_51'
Session ID: 0f859bed-35df-4eba-a472-3bc2efec4814
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Please use explicit wait instead of the Thread.sleep(5000), like in the next example.
It will provide you much clearer error regarding what you experience.
public void Test2() throws Exception{
new WebDriverWait(driver, 3).until(ExpectedConditions.visibilityOfElementLocated(By.id("cboMenu")))
driver.findElement(By.id("cboMenu")).click();
driver.findElement(By.xpath(".//*[#id='cboMenu/option[3]")).click();
}
Next, verify your button doesn't appear in different iFrame. If you do, change the iFrame to the one you element inside:
driver.switchTo().frame("IFRAME_ID");
The IFRAME_ID is taken from the DOM:
<iframe id="IFRAME_ID">
You can next change visibilityOfElementLocated to presenceOfElementLocated, that will verify that an element is present on the DOM but does not necessarily mean that the element is visible. It can be good clue to know if your webDriver is in the correct scope with the button you try to click.
Additional tip - scroll the button you want to click on into view. Thats could be also the reason to failure.
//element is WebElement
(JavascriptExecutor)driver.executeScript("arguments[0].scrollIntoView(true);", element);
this is solved my issue :)
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.context("WEBVIEW_com.openstream.cueme.services.workbench");
Thread.sleep(10000);
driver.findElementById("userId").sendKeys("sysadmin");
driver.findElementById("CuemePassword").sendKeys("MMNext13#");
Try below code
public void Test2() throws Exception{
Thread.sleep(5000);
driver.findElement(By.id("cboMenu")).click();
driver.findElement(By.xpath(".//*[#id='cboMenu']/option[3]")).click();

Categories

Resources