0

I've spent the last few days writing tests in Cucumber. The tests I've written so far work fine, I've been able to click objects, sendkeys over. No problem.

I've now gotten to these page elements that cannot be found no matter what selector I use. I've tried using wait, but even though they are clearly visible on the page, they can't be accessed.

This is happening in both table row elements that I want to click on, and a text input I want to sendkeys to. I've included the latter below.

 <input type="text" name="EMPLOYEE_label" value="" class="" 
 onkeypress="return dtPk(event,this);" onkeydown="return dtKd(event,this);" 
 onchange="dltCh(this,'EMPLOYEE__test');" size="30" wbvalid="true" 
isresolving="false">

Here is the code I am using at present.

webdriver = new ChromeDriver();
WebDriverWait wait = new WebDriverWait(webdriver, 30);  
wait.until(ExpectedConditions.visibilityOfElementLocated(By
    .name("EMPLOYEE_label")));

JOptionPane.showMessageDialog(null, "WebDriver =" + webdriver);
WebElement empIDTextInput  = webdriver.findElement(By.name("EMPLOYEE_label"));
empIDTextInput.sendKeys("Bennett");
Thread.sleep(1000);
gtaProxyPage.clickFindButton().click();
Thread.sleep(1000);

gtaProxyPage.checkAssociateBox().click();
gtaProxyPage.loadTimesheet().click();
Thread.sleep(2000);

EDIT: I changed the code to this. It more closely resembles what I started with

     Thread.sleep(30000); 
     //this calls for the input element by className.
    gtaProxyPage.UserEntersNumberUnderTimesheet().click();
    gtaProxyPage.clickFindButton().click();
    gtaProxyPage.checkAssociateBox().click();
    gtaProxyPage.loadTimesheet().click();

This is the error I'm getting now

 org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"class name","selector":"input.triggerButton"}

I switched what I"m doing to click a button that opens a modal, and allows me to use a text field within that. But the button is not being seen.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Jack Parker
  • 547
  • 2
  • 9
  • 32
  • **EMPLOYEE_IDS_label** does not exist, it should be **EMPLOYEE_label** instead ?? – Josh Dec 11 '18 at 21:01
  • No, that is not it, I changed some names before posting. – Jack Parker Dec 11 '18 at 21:03
  • What error message are you getting? (You should *always* include the full error message in any question). Have you checked to see if the locator is returning the right element? Is there more than one element on that page that matches? Try using `$$("input[name='EMPLOYEE_label']")` in the dev console... does it return 1? – JeffC Dec 11 '18 at 21:39
  • Also, `wait.until()` returns the element waited for so you can do, `WebElement empIDTextInput = wait.until(ExpectedConditions.visibilityOfElementLocated(By .name("EMPLOYEE_label")));` and not have to scrape the page again for the same element. – JeffC Dec 11 '18 at 21:42
  • org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.name: EMPLOYEE_label (tried for 30 second(s) with 500 milliseconds interval) – Jack Parker Dec 11 '18 at 21:53

1 Answers1

0

This error message...

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"class name","selector":"input.triggerButton"}

...implies that the no such element was found using the Locator Strategy with classname attribute as input.triggerButton.

Irespective of all the changes and manipulation done while publishing the relevant HTML within the question, to send a character sequence to the element:

<input type="text" name="EMPLOYEE_label" value="" class="" onkeypress="return dtPk(event,this);" onkeydown="return dtKd(event,this);" onchange="dltCh(this,'EMPLOYEE__test');" size="30" wbvalid="true" isresolving="false">

As the element is a dynamic element you have to induce WebDriverWait for the element to be clickable and you can use either of the following solutions:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input[name='EMPLOYEE_label'][onchange*='EMPLOYEE__test']"))).sendKeys("Bennett");
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='EMPLOYEE_label' and contains(@onchange, 'EMPLOYEE__test')]"))).sendKeys("Bennett");
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • So I have previously tried this. I add the following 2 lines of code. WebDriverWait timeSheetElement = new WebDriverWait(webdriver,100); timeSheetElement.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='tabs-1']/div/table/tbody/tr[1]/td[3]"))).sendKeys("Bennett"); However, it throws a NullPointerException when I do. The NPE can be attributed to the webdriver being used, but if I try to initialize a webdriver in the method, it just opens up a new driver, that doesn't relate to the actions being performed, so nothing still works. – Jack Parker Dec 12 '18 at 13:17
  • I edited the code to reflect what you wrote here. I have passed a webDriver into method which kills the NullPointer but the Expected Condition fails every time. public void userEntersWinUnderTimesheet(WebDriver webdriver) { WebDriverWait timeSheetElement = new WebDriverWait(webdriver,100); timeSheetElement.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='EMPLOYEE_label'][onchange*='EMPLOYEE_IDS']"))).sendKeys(Keywords.ASSOC_LAST_NAME); – Jack Parker Dec 12 '18 at 14:26