1
votes

Its a very simple script, but I need help.

The webdriver clicks the google search button when there are no suggestions listed for the text typed (for eg macintosh). But when suggestions appear, how do I still make the webdriver click on the Google Search button. My code below:

package newProj;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.remote.RemoteWebDriver;


public class Google {


public static void main(String[] args) throws InterruptedException {



    System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");

    RemoteWebDriver driver = new ChromeDriver();

    driver.get("http://www.google.com");
    driver.manage().window().maximize();
    driver.findElementById("lst-ib").sendKeys("macintosh");

    WebElement gs = driver.findElementByXPath("//input[@value = 'Google Search']");

    gs.click();
    System.out.println("Search Done");

    driver.close();
}

}

but getting the below error. Pls help

Starting ChromeDriver 2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab) on port 3288 Only local connections are allowed. Jun 27, 2018 12:14:37 PM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: OSS true Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (598, 411). Other element would receive the click: ...
(Session info: chrome=67.0.3396.87) (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T15:15:03.216Z' System info: host: 'HDC0007030', ip: '10.50.90.19', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_73' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.40.565498 (ea082db3280dd6..., userDataDir: C:\Users\CSS116~1\AppData\L...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 67.0.3396.87, webStorageEnabled: true} Session ID: f4700c020ed7f67bd9e46a3c70fb4b02 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:214) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166) at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40) at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80) at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543) at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:276) at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:83) at newProj.Google.main(Google.java:33)

2

2 Answers

0
votes

driver.navigate().to("http:\google.com");

    driver.findElement(By.cssSelector("input[title='Search']")).sendKeys("sele");

    List<WebElement> list=driver.findElements(By.xpath("//*[@class='sbsb_b']/li[*]"));

    Iterator<WebElement> itr=list.listIterator();
    while(itr.hasNext()){

        WebElement element=itr.next();

        if(element.getText().equalsIgnoreCase("selenium webdriver")){

            element.click();
            break;
        }
    }
0
votes

It's a tiny mistake. Replace click() by submit(), like below -

WebElement gs = driver.findElementByXPath("//input[@value = 'Google Search']");

gs.submit(); 

It will work.