2

I am trying to automate the code of submit resume page, it consists on smart textboxes, which gives suggestions below as soon as you type few text in it. you need to select and input into the textbox from the suggestions given. Below is the code and the url:

WebDriver w= new FirefoxDriver();
w.get("https://www.hrmantra.com/LetsLead/18_Recruitment/SubmittResume.aspx?cn=LetsLead");
w.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
w.findElement(By.id("StCityName_txtSpeedName")).sendKeys("Mumbai");

Only sendkeys command is not working as the entered value has to be selected and the control needs to be closed.

2
  • It can many reason. Please share your html code. Commented Sep 27, 2015 at 8:45
  • @MahsumAkbas the URL is posted in the question. Commented Sep 27, 2015 at 22:04

3 Answers 3

1

The text box has a select drop down box which appears dynamically on entering the city from it the user selects his city but this select box is inside an iframe (iframe id : SpeedTyperFrameID)so we need to switch to it and then access the select box

Below is the code

    WebElement city = driver.findElement(By.xpath("//*[@id='StCityName_txtSpeedName']"));

    city.click();

    city.sendKeys("chennai");

   //wait for the iframe to load and then switch to it

    new WebDriverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("SpeedTyperFrameID")));

    Thread,sleep(3000);//added just to show u the effect remove it      
    WebElement byValue = driver.findElement(By.id("SelectList"));

    //using select class to select the element by its text      
    Select select = new Select(byValue);

    select.selectByVisibleText("Chennai");

    //switch back to default content inorder to access other elements outside the iframe

    driver.switchTo().defaultContent();

I have tested the above code it is working fine

Kindly get back if you have any queries.

Sign up to request clarification or add additional context in comments.

Comments

0

Ideally, After you type partial text into input you have to find all suggestions from dropdown list and click on it. Perhaps, try to use enter key, but I am not aware that it will help

element.sendKeys("Mumbai" + Keys.ENTER)

2 Comments

@Vicky the page also consist of qualification section, where i need to click on 'add qualification' button , which opens in a new window , i select and add the qualification, switch back to parent window. But on automating the same , while clicking on 'Add Qualification' button it opens the new window ,but the session gets expired. attaching the code for your reference...please help
String parentHandle = w.getWindowHandle(); w.findElement(By.xpath("//.//*[@id='lbAddQualification']")).click(); for (String winHandle : w.getWindowHandles()) { w.switchTo().window(winHandle); // switch focus of WebDriver to the next found window handle (that's your newly opened window) e=new Select(w.findElement(By.xpath("//.//*[@id='lstlist']"))); e.selectByVisibleText("A Level DOEACC"); w.findElement(By.xpath("//.//*[@id='Btnconadd']")).click(); w.findElement(By.id("BtnAdd")).click(); } w.switchTo().window(parentHandle);
0

It's because there is no ID of id=StCityName_txtSpeedName on the page. You don't use id=... for the ID, you just type the ID.

See below.

w.findElement(By.id("StCityName_txtSpeedName")).sendKeys("Mumbai");

2 Comments

@MahsumAkbas I have edited the code ,the error is not coming but still the problem is resolved,I need to select the Input(Mumbai) from the suggestions of the control, and SendKeys is only typing into it and not selecting into it. As a result of which , suggestions prompted by the control while typing remains open and I am unable to move the focus and type into other textboxes.
I have edited the code ,the error is not coming but still the problem is resolved,I need to select the Input(Mumbai) from the suggestions of the control, and SendKeys is only typing into it and not selecting into it. As a result of which , suggestions prompted by the control while typing remains open and I am unable to move the focus and type into other textboxes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.