0

While passing a value, system selects a different value from the drop down in selenium web driver.

Following is the code written:-

driver.findElement(By.xpath(".//*[@id='ctl00_ContentPlaceHolder1_Users_RadGrid_ctl00_ctl02_ctl03_RCNewJobType_Input']")).click();

driver.findElement(By.xpath(".//*[@id='ctl00_ContentPlaceHolder1_Users_RadGrid_ctl00_ctl02_ctl03_RCNewJobType_Input']")).sendKeys(mystring[5]);

driver.findElement(By.xpath(".//*[@id='ctl00_ContentPlaceHolder1_Users_RadGrid_ctl00_ctl02_ctl03_RCNewJobType_Input']")).sendKeys(Keys.ARROW_DOWN,Keys.ENTER);
5
  • 1
    You can use 'Select' class for selecting value from the drop down unless you don't want to use it. Select class is easier to use while working with drop-down
    – Minion4
    Commented Dec 8, 2015 at 13:30
  • How is that related to Quality Center, if the code is for Selenium/Web Driver.
    – dzieciou
    Commented Dec 8, 2015 at 13:30
  • @Minion4: I also tried to use "Select" but its giving following error Exception in thread "main" org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "input" Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 02:56:46' Code written for above is: Select jobtype = new Select(driver.findElement(By.id("ctl00_ContentPlaceHolder1_Users_RadGrid_ctl00_ctl02_ctl03_RCNewJobType_Input"))); jobtype.selectByVisibleText(mystring[5]);
    – user15587
    Commented Dec 9, 2015 at 7:41
  • I think you should use selectByValue.
    – Minion4
    Commented Dec 9, 2015 at 15:44
  • I tried using it, but its not working. Is there any other way of doing it?
    – user15587
    Commented Dec 23, 2015 at 7:37

1 Answer 1

1

As Minion4 pointed out, you want to use 'select' and not 'sendKeys'. You can select by Value, ID, Index, or Visible Text.

1
  • I had the same thought. But in this question the user doesn't want to use Select. So was wondering if it could be a similar problem
    – Minion4
    Commented Dec 8, 2015 at 18:16

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.