0

HTML:

<input name="txtAnswer" type="text" maxlength="20" id="txtAnswer" class="box1">

Code trials:

driver.findElement(By.xpath("//table[@id='tblSecurityAnswer']//tbody//tr[2]//td[2]//input[@id='txtAnswer']")).sendKeys("green");

and also:

driver.findElement(By.cssSelector("//tr:nth-child(1) > td > table > tbody >
    // tr:nth-child(2) > td:nth-child(2)"));

public static void main(String[] args) throws InterruptedException {
    WebDriver driver;

    // IE webdriver
    // System.setProperty("webdriver.ie.driver", "C:\\IEDriverServer.exe");
    // driver = new InternetExplorerDriver();

    System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
    driver = new ChromeDriver();

    // Maximize the browser window
    driver.manage().window().maximize();

    // navigate to specified url
    driver.get("http://dxbqcapp01/molforms/login.aspx");

    driver.findElement(By.id("txtUserName")).sendKeys("MS200963915");
    driver.findElement(By.id("txtPassword")).sendKeys("test@123");
    driver.findElement(By.xpath("//input[@type='submit' and @value='Submit']")).sendKeys(Keys.ENTER);
    driver.findElement(By.id("txtAnswer")).sendKeys("green");
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Ali Sultan
  • 13
  • 6
  • 1
    Update the error stack trace – Fury Apr 21 '19 at 15:05
  • Have you checked to see if your element is in an `IFRAME`? Have you tried a wait? Also, please edit your question and add what isn't working, error/exception messages, etc. – JeffC Apr 22 '19 at 19:43
  • No element not in IFRAME. and i tried to wait but also not work , error that appear is org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"name","selector":"txtAnswer"} – Ali Sultan Apr 23 '19 at 05:22
  • can you share the html script of the table and element as well – Sivateja.koppineedi Apr 23 '19 at 12:04
  • HTML for element is () .but after i run the code and i got error that unable to locate element, when try to inspect element again at automated chrome page it view this HTML:
    – Ali Sultan Apr 24 '19 at 04:55
  • please find recording video for my test case https://www.screencast.com/t/uddlZPT8HpUD – Ali Sultan Apr 24 '19 at 05:06
  • i am not get any replay about my question – Ali Sultan Apr 28 '19 at 04:41

1 Answers1

0

The error stack trace would have helped us to debug your issue in a better way. However to send a character sequence to the desired element you have to induce WebDriverWait for the element to be clickable and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.box1#txtAnswer"))).sendKeys("green");
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='box1' and @id='txtAnswer']"))).sendKeys("green");
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352