I am working with selenium webdriver with java.
The issue that I faced is Drag and drop not working with selenium 3 and firefox driver
I'm getting the below error:
org.openqa.selenium.UnsupportedCommandException: POST /session/92189939-94cc-4327-bfb0-72d66621d2f2/moveto did not match a known command
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: 'TADT063', ip: '192.168.0.195', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_20'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=C:\Users\Amrutha.U\AppData\Local\Temp\rust_mozprofile.l2Myb7jgbekD, rotatable=false, timeouts={implicit=0, page load=300000, script=30000}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=52.0, platformVersion=6.1, moz:processID=4308, browserName=firefox, platformName=windows_nt}]
Session ID: 92189939-94cc-4327-bfb0-72d66621d2f2
Can anybody help me?
Code :
public void selectQuestions() throws InterruptedException, AWTException {
Thread.sleep(3000);
WebElement selectquestions = webElement("VAR_SELECTTOP5QUESTIONS");
selectquestions.click();
Thread.sleep(10000);
Actions builder = new Actions(driver);
Action drag = builder.clickAndHold(webElement("VAR_SELECTQUESTIONS")).build();
drag.perform();
Point coordinates = webElement("VAR_SELECTEDQUESTIONS").getLocation();
Robot robot = new Robot();
robot.mouseMove(coordinates.getX() + 280, coordinates.getY() + 120);
Thread.sleep(3000);
WebElement questions = webElement("VAR_SELECTEDQUESTIONS");
questions.click();
Thread.sleep(1000);
WebElement questionNextButton = webElement("VAR_QUESTION_NEXTBUTTON");
questionNextButton.click();
Thread.sleep(1000);
}
Related
package automationFramework;
import java.awt.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.lang.IllegalStateException;
public class Second_Practise {
public static void main(String[] args) throws InterruptedException {
String URL = "https://accounts.google.com/signin";
WebDriver driver;
System.setProperty("webdriver.gecko.driver", "D:\\geckodriver-v0.14.0-win64\\geckodriver.exe");
driver =new FirefoxDriver();
driver.get(URL);
WebElement Email = driver.findElement(By.id("identifierId"));
Email.sendKeys("dialogspp");
WebElement Next = driver.findElement(By.id("identifierNext"));
Next.click();
Thread.sleep(2000);
WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//*[#id='password']/div[1]/div/div[1]/input")));
WebElement Password = driver.findElement(By.xpath(".//*[#id='password']/div[1]/div/div[1]/input"));
Password.sendKeys("dialogapp");
WebElement PassNext = driver.findElement(By.id("passwordNext"));
PassNext.click();
Thread.sleep(2000);
//WebElement gmail = driver.findElement(By.xpath("//a[#href='https://mail.google.com']"));
WebElement myDynamicElement2 = (new WebDriverWait(driver, 10)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[#href='https://mail.google.com']")));
myDynamicElement2.click();
Thread.sleep(2000);
WebElement myDynamicElement3 = (new WebDriverWait(driver, 10)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[#gh='cm']")));
myDynamicElement3.click();
}
}
I am using this piece of code to send an email, but on clicking "Compose" button i am getting the exception. i.e.
Jun 20, 2017 2:57:37 PM org.openqa.selenium.support.ui.ExpectedConditions findElement
WARNING: WebDriverException thrown by findElement(By.xpath: //div[#gh='cm'])
org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.xpath: //div[#gh='cm']
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: 'unknown', revision: '86a5d70', time: '2017-02-16 07:47:51 -0800'
System info: host: 'ANUM-PC', ip: '172.16.11.162', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: driver.version: unknown
at org.openqa.selenium.support.ui.ExpectedConditions.lambda$findElement$0(ExpectedConditions.java:896)
at java.util.Optional.orElseThrow(Unknown Source)
at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:895)
at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:41)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:205)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:201)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:234)
at automationFramework.Second_Practise.main(Second_Practise.java:35)
Exception in thread "main" org.openqa.selenium.JavascriptException: Error: Permission denied to access property "navigator"
Build info: version: 'unknown', revision: '86a5d70', time: '2017-02-16 07:47:51 -0800'
System info: host: 'ANUM-PC', ip: '172.16.11.162', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, marionette=true, appBuildId=20161031133903, version=, platform=XP, proxy={}, command_id=1, specificationLevel=0, acceptSslCerts=false, browserVersion=47.0.2, platformVersion=6.1, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=Firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=Windows_NT, device=desktop, firefox_profile=UEsDBBQACAgIACp31EoAAAAAAAAAA...}]
Session ID: b216dfb9-b672-4cd2-b7cc-087c74789afa
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:127)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:93)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:42)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)
at org.openqa.selenium.remote.RemoteWebElement.isDisplayed(RemoteWebElement.java:315)
at org.openqa.selenium.support.ui.ExpectedConditions.elementIfVisible(ExpectedConditions.java:302)
at org.openqa.selenium.support.ui.ExpectedConditions.access$100(ExpectedConditions.java:41)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:205)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:201)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:234)
at automationFramework.Second_Practise.main(Second_Practise.java:35)
I am able to access the element using firepath but error is still been there. Any suggestions?
I try to execute this script:
public class BuyMenShirt {
public static void main(String[] args) throws InterruptedException
{
//Firefox driver setup
String driverPath = "C:\\Users\\RW\\geckodriver-master\\";
System.setProperty("webdriver.gecko.driver", driverPath + "geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.gap.com");
WebElement menlink = driver.findElement(By.id("division5063"));
menlink.click();
WebElement shirtlink = driver.findElement(By.cssSelector("a.sidebar-navigation--category--link[href=/browse/category.do?cid=15043]"));
shirtlink.click();
}
}
However, I got this error:
Nov 01, 2016 2:10:13 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
JavaScript error: http://www.gap.com/, line 20471: TypeError: personalizationService.model.personalizationData.personalizationInfoV1.featureSelections is null
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: 'RW-PC', ip: '192.168.0.105', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_112'
Driver info: driver.version: RemoteWebDriver
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, marionette=true, firefoxOptions={args=[], prefs={}}, appBuildId=20161019084923, version=, platform=XP, proxy={}, command_id=1, specificationLevel=0, acceptSslCerts=false, processId=1692, browserVersion=49.0.2, platformVersion=10.0, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=windows_nt, device=desktop}]
Session ID: 9c166d1b-3391-4ed9-8fac-3afe6d09b13f
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:622)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:368)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByCssSelector(RemoteWebDriver.java:465)
at org.openqa.selenium.By$ByCssSelector.findElement(By.java:430)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360)
at BuyMenShirt.main(BuyMenShirt.java:27)
Caused by: java.lang.IllegalArgumentException: expected one element but was: <org.openqa.selenium.remote.ErrorCodes$KnownError#cd2dae5, org.openqa.selenium.remote.ErrorCodes$KnownError#4973813a>
at com.google.common.collect.Iterators.getOnlyElement(Iterators.java:322)
at com.google.common.collect.Iterables.getOnlyElement(Iterables.java:284)
at org.openqa.selenium.remote.ErrorCodes.toStatus(ErrorCodes.java:138)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:92)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:42)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
... 5 more
Did I do something wrong? I notice I got some JavaScript error right before UnreachableBrowserException. Does it matter?
When looking at this post:
I got most of my solution but the VK_ENTER at the end did not take me back to the web page which leads to another issue of getting back into view of the page and not the cropper tool where the image is placed.
Can someone let me know what I need to do to get this to work?? Thanks!!
Here is the code:
public static void setClipboardData(String string) {
StringSelection stringSelection = new StringSelection(string);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);
}
And that is what i do, just after opening the "open" window:
setClipboardData("C:\\path to file\\example.jpg");
//native key strokes for CTRL, V and ENTER keys
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
Here is a link to a screen recording of how this is supposed to work(resizing and moving is not relevant to the issue)Upload profile picture]1
One of the issues is that the VK_ENTER is never done to leave file explorer and return to the web page. If I do it manually while the test is running the Save button is never found. Here is the error for that:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"/html/body/div[12]/form/div/div[1]/button[1]"}
Command duration or timeout: 30.10 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: host: 'Janet-PC', ip: '192.168.56.1', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_66'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=43.0.4, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: b7ceb493-af57-4290-a585-bc237e043848
*** Element info: {Using=xpath, value=/html/body/div[12]/form/div/div[1]/button[1]}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
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:647)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:353)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:490)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:345)
at groupPhotoUploadTest.groupPhotoUploadTest.main(groupPhotoUploadTest.java:54)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"/html/body/div[12]/form/div/div[1]/button[1]"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: host: 'Janet-PC', ip: '192.168.56.1', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_66'
Driver info: driver.version: unknown
at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/Janet/AppData/Local/Temp/anonymous8445833340663492444webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:10659)
at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/Janet/AppData/Local/Temp/anonymous8445833340663492444webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:621)
I have tried the Actions object as well as JavascriptExecutor and neither seem to work.
Here is the complete code:
package groupPhotoUploadTest;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
public class groupPhotoUploadTest {
private static WebDriver driver;
private static String baseUrl;
public static void main(String[] args) throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://loadtest1.staging.brio.viddler.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get(baseUrl + "/");
driver.findElement(By.linkText("Login")).click();
driver.findElement(By.name("email_address")).clear();
driver.findElement(By.name("email_address")).sendKeys("jfrank#viddler.com");
driver.findElement(By.name("password")).clear();
driver.findElement(By.name("password")).sendKeys("Annie0308!");
driver.findElement(By.cssSelector("button.button")).click();
driver.findElement(By.linkText("Load Test1")).click();
driver.findElement(By.linkText("Manage Site")).click();
driver.findElement(By.linkText("Manage")).click();
driver.findElement(By.xpath("//div[#id='container']/div/table/tbody/tr[5]/td[6]/a")).click();
driver.findElement(By.linkText("Upload Logo")).click();
driver.findElement(By.name("image_file")).clear();
driver.findElement(By.name("image_file")).click();
// driver.findElement(By.name("image_file")).sendKeys("C:\\Users\\Janet\\Pictures\\P8291157.JPG");
setClipboardData("C:\\Users\\Janet\\Pictures\\P8291157.JPG");
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
// robot.delay(5000);
/* WebElement saveLink = driver.findElement(By.xpath("/html/body/div[12]/form/div/div[1]/button[1]"));
Actions actions = new Actions(driver);
actions.moveToElement(saveLink);
actions.click();
actions.build().perform(); */
JavascriptExecutor jse = (JavascriptExecutor)driver;
WebElement saveLink = driver.findElement(By.xpath("/html/body/div[12]/form/div/div[1]/button[1]"));
jse.executeScript("arguments[0].click();", saveLink);
// driver.findElement(By.cssSelector("button.submit.button")).click();
}
public static void setClipboardData(String string) {
StringSelection stringSelection = new StringSelection(string);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);
}
public void tearDown() throws Exception {
driver.quit();
}
}
Finally have it working. Here is the complete code. Had to use the cssSelector and not the xpath:
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ENTER);
Thread.sleep(3000);
robot.keyRelease(KeyEvent.VK_ENTER);
Thread.sleep(3000);
Thread.sleep(5000);
WebElement saveLink = driver.findElement(By.cssSelector("button.submit.button"));
Actions actions = new Actions(driver);
actions.moveToElement(saveLink);
actions.click();
actions.build().perform();
Thread.sleep(5000);
WebElement submitLink = driver.findElement(By.cssSelector("input.button"));
actions.moveToElement(submitLink);
actions.click();
actions.build().perform();
I am trying to write a word in google search editbox and capture all the related list item and display it. But while doing so i got Got a exception
org.openqa.selenium.InvalidElementStateException: Element is disabled and so may not be used for actions. I went through the same exception related question and according to them changed my code but none of them help.
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.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
public class AutoIt {
public static void main(String[] args){
WebDriver window;
FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(false);
window = new FirefoxDriver(profile);
try{
window.get("https://www.google.co.in/");
window.manage().window().maximize();
window.findElement(By.id("gs_htif0")).sendKeys("Shantanu Nandan");
window.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
List<WebElement> list=window.findElements(By.xpath("//td[#style='width: 100%;']/span"));
window.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
for(WebElement data:list){
System.out.println(data.getAttribute("value"));
}//for
}//try
catch(Exception e){
System.out.println("Got a exception");
e.printStackTrace();
window.close();
}//catch
finally{
System.out.println("Finally Block Executed ....");
window.close();
window.quit();
}//finally
}//main
}//class
Exception which i got for this code
org.openqa.selenium.InvalidElementStateException: Element is disabled and so may not be used for actions
Command duration or timeout: 47 milliseconds
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: 'omega-d52b83806', ip: '10.0.0.4', os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0_45'
Session ID: d29ef567-95a8-47ce-bf84-c510cbb2756d
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, browserConnectionEnabled=true, webStorageEnabled=true, nativeEvents=false, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=29.0.1}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:89)
at AutoIt.main(AutoIt.java:21)
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Element is disabled and so may not be used for actions
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: 'omega-d52b83806', ip: '10.0.0.4', os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0_45'
Driver info: driver.version: unknown
at <anonymous class>.fxdriver.preconditions.enabled(file:///C:/DOCUME~1/OMEGA/LOCALS~1/Temp/anonymous7567378475668954944webdriver-profile/extensions/fxdriver#googlecode.com/components/command_processor.js:8185)
at <anonymous class>.DelayedCommand.prototype.checkPreconditions_(file:///C:/DOCUME~1/OMEGA/LOCALS~1/Temp/anonymous7567378475668954944webdriver-profile/extensions/fxdriver#googlecode.com/components/command_processor.js:10814)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/DOCUME~1/OMEGA/LOCALS~1/Temp/anonymous7567378475668954944webdriver-profile/extensions/fxdriver#googlecode.com/components/command_processor.js:10831)
at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/DOCUME~1/OMEGA/LOCALS~1/Temp/anonymous7567378475668954944webdriver-profile/extensions/fxdriver#googlecode.com/components/command_processor.js:10836)
at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/DOCUME~1/OMEGA/LOCALS~1/Temp/anonymous7567378475668954944webdriver-profile/extensions/fxdriver#googlecode.com/components/command_processor.js:10778)
Finally Block Executed ....
You have selected the wrong element.
Use the below one for search text box
wb=window.findElement(By.name("q"));
Use the below for getting output suggestions.
List<WebElement> list = window.findElements(By.className("gsq_a"));
To get the values from the list, use getText() method instead of getAttribute().
for (WebElement data : list) {
System.out.println(data.getText());
}
Please try the below code
public class AutoSuggest {
WebDriver driver;
#Before
public void seup()
{
driver= new FirefoxDriver();
}
#Test
public void test_autosuggest()
{
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("https://www.google.co.in/");
driver.findElement(By.xpath("//div[#id='gs_lc0']//input[#id='gbqfq']")).sendKeys("h");
WebElement wb=driver.findElement(By.xpath("//td[#class='gssb_e']"));
List<WebElement> links= wb.findElements(By.tagName("div"));
System.out.println("the total "+links.size());
for (int i=0;i<links.size();i++)
{
System.out.println(links.get(i).getText());
}
}
}
static WebDriver driver = new FirefoxDriver();
public static void main(String[] args) throws IOException, InterruptedException {
// TODO code application logic here
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter base url....!!!");
String baseurl = br.readLine();
connection c= new connection();
c.makeConnection(driver,baseurl);
JavascriptExecutor js;
if (driver instanceof JavascriptExecutor) {
js = (JavascriptExecutor)driver;
js.executeScript("alert('hello world');");
}
Following error occurs
Exception in thread "main" org.openqa.selenium.UnhandledAlertException: Modal dialog present: hello world
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'
System info: host: 'comp74', ip: '192.168.0.74', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_17'
Session ID: f6ba3a2b-87d4-4192-ad1a-94cf260d8f6e
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, browserConnectionEnabled=true, webStorageEnabled=true, nativeEvents=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=26.0}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at org.openqa.selenium.remote.ErrorHandler.createUnhandledAlertException(ErrorHandler.java:174)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:141)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:332)
at org.openqa.selenium.remote.RemoteWebDriver.findElementsByXPath(RemoteWebDriver.java:408)
at org.openqa.selenium.By$ByXPath.findElements(By.java:358)
at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:295)
at javaapplication4.count.linkCount(count.java:27)
at javaapplication4.JavaApplication4.main(JavaApplication4.java:34)
Is per my understanding. After executing an alert if you try to do any other operation in the page when the alert already exists this errors comes. Are you providing the actual code?
Exception shows
at javaapplication4.count.linkCount(count.java:27)
at javaapplication4.JavaApplication4.main(JavaApplication4.java:34)
as per above stacktrace you do something in linkCount.
If you have anycode after .executeScript("alert('hello world' line. Please comment them and then check.