2

There are some details.

  • code:

        System.setProperty("webdriver.ie.driver", "res\\IEDriverServer.exe");
        System.setProperty("webdriver.ie.driver.loglevel", "TRACE");
        System.setProperty("webdriver.ie.driver.logfile", "log\\selenium.log");
        DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();        ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
        WebDriver driver = new InternetExplorerDriver(ieCapabilities);
        driver.navigate().to("http://www.google.com");
        //System.out.println(driver.getPageSource());
        driver.findElement(By.id("lst-ib")).sendKeys("selenium");
        driver.findElement(By.name("btnK")).click();
    

- console ouput:

Started InternetExplorerDriver server (64-bit)
2.44.0.0
Listening on port 41180
Log level is set to TRACE
Log file is set to C:\Users\xxxxx\workspace\SeleniumTest\log\selenium.log
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with id == lst-ib (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 342 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:03:00'
System info: host: 'xxxxxx', ip: 'xxxxx', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_25'

  • question:

    It works on ChromeDriver , I can input "selenium" to input field and serach it successfully , but why InternetExplorerDriver get this Exception ?

  • note:

    Some body said that the site should be in "Trusted" for Windows server installation , he was not sure why, but adding google.com to trusted solved an issue . I don't know whether the way can resolve it , because my company make me impossiable to set it .

  • update1

    I have tried to add wait statement to my code , but get the below error .

    Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 90 seconds waiting for visibility of element located by By.id: lst-ib Caused by: org.openqa.selenium.NoSuchElementException: Unable to find element with id == lst-ib (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 309 milliseconds

  • solution

The code can work now , finally code like this :

            System.setProperty("webdriver.ie.driver", "res\\IEDriverServer.exe");
            System.setProperty("webdriver.ie.driver.loglevel", "TRACE");
            System.setProperty("webdriver.ie.driver.logfile", "log\\selenium.log");
            DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
         ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
            WebDriver driver = new InternetExplorerDriver(ieCapabilities);//
            driver.navigate().to("http://www.google.com");
            WebElement text =driver.findElement(By.name("q"));
            text.sendKeys("selenium");
            text.submit();

I need to inform that I have copied the code to my colleague computer to run it , In the beginning , I can work successfully ,but my colleague not ; we tried serveral times , come out the same result , we found IEDriverServer.exe didn't be closed ervery time , finally he restarted the computer , So strange , the code can work successfully . I don't know why . Maybe some environment factors affected IEDriverServer.exe or other things. .

Lahne
  • 31
  • 1
  • 4
  • Try adding wait statement to your code. Ref :http://stackoverflow.com/questions/23186851/how-to-locate-and-type-something-in-the-textbox/23192948#23192948 – Sriram Nov 05 '14 at 13:59
  • I try to add wait statement to my code , like your Ref , but get error like this : org.openqa.selenium.TimeoutException: Timed out after 90 seconds waiting for visibility of element located by By.id: lst-ib – Lahne Nov 06 '14 at 01:33
  • ``. This is the HTML snippet of google search box – Sriram Nov 06 '14 at 06:13
  • Id of search is 'gbqfq'. Please try using that. Also please try using Xpath/CSS for identification – Sriram Nov 06 '14 at 06:13
  • yes , google seem to create it's main page dynamically , Accessing through different browsers , source code is different . Now I change it correct by name=q. – Lahne Nov 06 '14 at 07:22

3 Answers3

1

I am curious what element you are trying to locate on google.com and equally curious what element Chrome is locating with that locator. When I check google.com and search for an element with an id of lst-ib there is no result.

The id for the input search field on the main google search page when I checked it is: id=gbqfq.

  • yes , google seem to create it's main page dynamically , Accessing through different browsers , source code is different . Now I change it correct by name=q. – Lahne Nov 06 '14 at 07:21
  • I believe you are confused on your locating strategy. An element can have both a name and an ID. In this case, the google.com input box ID=bgqfq and name=q. These are the same element, there is nothing dynamic happening, they are the same element with various properties. If IE is finding element by name and not by ID, I have no idea why that would be happening. –  Nov 06 '14 at 13:58
  • I got what your said , An element can have both a name and an ID ; but I found that the google.com input box ID=null and name=q if we visit by IE , but ID=lst-ib and name=q by Chrome . [google.com](https://www.google.com.hk/?gfe_rd=cr&ei=mSxcVN-zNM3D8AWu-IDwBQ) ,you can visit above link using different Browser. Input box ID is different . – Lahne Nov 07 '14 at 02:36
  • Id value is different ,so I need find element by name. Thanks for your answer , It can work now . – Lahne Nov 07 '14 at 02:45
  • I understand what you're saying, and glad it works for you. I've checked with both IE and Chrome on my end and they all have the same element attributes (as expected). Google is not creating their elements with different properties for different browsers. Something is odd about your configuration. –  Nov 07 '14 at 02:56
0

As @TheBear said, I also didn't find any element with id 'lst-ib'.
You can change the code to the below one to make it work:

driver.findElement(By.id("gbqfq")).sendKeys("selenium");

As 'gbqfq' is in fact the id of the search box, this works correctly for me in IE and FF.

Subh
  • 4,354
  • 1
  • 13
  • 32
  • yes , It's a mistake ; as you say , It can work now . – Lahne Nov 06 '14 at 08:05
  • If it has helped you out, please mark it as answer so that others who have faced similar problems, will be benefitted. Thanks. :) – Subh Nov 06 '14 at 08:40
0

Lahne,

I made a simple test with your first code it worked perfectly in my framework. The problem you could be having is perhaps some timming issue with the page not being fully loaded in the browser before you searched for the lst-ib element.

WebDriver should lock your code until all elements are loaded, but it only works for HTML static elements, things loaded dynamically (by ajax) are not covered, so, watch out for this.

Try your first code again with a sleep before you the looking for lst-ib

It worked on my first attempt.

@Test
public void testIE() {
    getDriver().navigate().to("http://www.google.com");
    getDriver().findElement(By.id("lst-ib")).sendKeys(
            "selenium" + Keys.ENTER);
    Utils.sleep(5000);
}
cbaldan
  • 522
  • 8
  • 16