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

Hi,

Please use below code, if not worked then let me know, if worked then ACCEPT the answer 🙂 .


import java.util.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 org.testng.annotations.Test;
public class Auto_Suggestions {

@Test

public void select() throws InterruptedException

{

WebDriver d = new FirefoxDriver();

d.manage().window().maximize();

d.get("http://www.monsterindia.com/");
d.findElement(By.id("fts_id")).sendKeys("software");
WebElement link = d.findElement(By.id("ui-id-1"));

List<WebElement> links = link.findElements(By.tagName("li"));

for(int i=0; i<links.size();i++)

{

System.out.println(links.get(i).getText());

}

WebElement myDynamicElement = (new WebDriverWait(d, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("ui-id-11")));

d.findElement(By.id("ui-id-11")).click();

d.findElement(By.className("mn_findbtn")).click();
}

}

Vice Professor Answered on November 16, 2014.
Add Comment

Your Answer

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