RE: Problem in handling auto suggestion

Hi All,

I was writing a webdriver code to handle auto suggestion (monsterindia.com) for the homa page “keywork” field. but it is unable to locate the suggested element..please help me…

package Simple;

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.interactions.Actions;
import org.testng.annotations.Test;

public class AutoSuggestion {
@Test
public void select() throws InterruptedException
{
WebDriver d = new FirefoxDriver();
d.manage().window().maximize();
d.get(“http://www.monsterindia.com/“);
d.findElement(By.cssSelector(“‪#‎fts_id‬“)).sendKeys(“soft”);
Actions a = new Actions(d);

WebElement w = d.findElement(By.cssSelector(“‪#‎ui‬-id-4″));//this line is unable to locate element.
a.moveToElement(w).build().perform();
Thread.sleep(5000);
a.click(w).build().perform();

}

}

snpanigrahi9 Train Asked on November 15, 2014 in Selenium WebDriver.

Hello,

After running your code I am getting below error message.

Note: Please let us know what you are trying to do here OR give a steps.


Unable to locate element: {"method":"css selector","selector":"?#?fts_id?"}

Command duration or timeout: 150 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:02:37'

on November 16, 2014.

@Sachin: correct, code is not working.

Action should not use here, key, mouse actions are different and webdriver actions. :).

Up voted for your solution.

on November 16, 2014.
Add Comment
3 Answers

HId.manage().window().maximize();
d.get(“http://www.monsterindia.com/“);
d.findElement(By.cssSelector(“‪#‎fts_id‬“)).sendKeys(“soft”);

Thread.sleep(5000);    // as it will take some time  to appear suggestions
Actions a = new Actions(d);

WebElement w = d.findElement(By.cssSelector(“‪#‎ui‬-id-4″));//this line is unable to locate element.

Vice Professor Answered on November 16, 2014.

Thanks ankit…

on November 16, 2014.

@snpanigrahi9 :Why you are using Actions here?, for any purpose?. Can’t we do in other way?.

on November 16, 2014.

Please go through this link and will come to know the difference:ACTIONS

on November 16, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.