4

So I have an input element on a page and I need to click on it to go to another page. Problem is that when I user click() or submit() on the element nothing happens. I have a custom highlight method that is working so I can see that I am actually on the correct element. The click() just seems to not be working on it for some unknown reason.

Here is the html I'm working with

<TBODY>
<TR style="" class=" STDLISTROW_O" onmouseover=listMouseOver(this);  onmouseout=listMouseOut(this); saveBG>
<TD class=STDLISTBTN>
<INPUT style="COLOR: " onmouseover="listBtnMouseOver(this);   window.status = this.status_txt;" onmouseout="listBtnMouseOut(this); window.status = '';" onclick=" event.cancelBubble = true;  if (this.getAttribute('clicked') == 'false')  { document.location.href = 'client$.startup?P_CLIENT_ID=7605677'; this.setAttribute('clicked', 'true'); } " value=ECR type=button status_txt="client$.startup?P_CLIENT_ID=7605677" clicked="false" saveBtnBG saveBtnC></TD>

Here is my Selenium/Java method

public void clickECRButtonWithID(String clientID) {
    log.info("Click the ECR button for the row with client id: " + clientID);
    WebElement idRow = driver.findElement(By.xpath("//td[contains(text(),'"
            + clientID + "')]/ancestor::tr"));
    WebElementExtender.highlightElement(idRow);
    WebElement ecrButton = driver.findElement(By.cssSelector("input[value='ECR']"));
    WebElementExtender.highlightElement(ecrButton);
    ecrButton.click();
}

I have also tried isolating the parent td of the input and clicking on it with no luck. I'm at a loss here.

  • I need to add that I am using Internet Explorer Driver (IEDriverServer) and am on IE9 browser. Unfortunately that's all this application will run on!
4
  • The fact that the input does not have a 'type' attribute has something to do with it. Does it work if the input has the attribute type='button' ? Commented Jan 20, 2014 at 19:46
  • @SteveCrawford It does have the attribute type='button'. Look at the very end past all the javascript. Commented Jan 20, 2014 at 19:50
  • Ahh, sorry I missed it since it doesn't have quotes around it. I'm not 100% but this doesn't seem to be valid html, what are 'saveBtnBG' and 'saveBtnC', should they be classes? Commented Jan 20, 2014 at 20:17
  • @SteveCrawford I'm sure it's not valid html. The application is a mess and I have no access to change anything or ad IDs to any element. It's a challenge for sure! Commented Jan 20, 2014 at 21:34

2 Answers 2

7

First try other browsers like Firefox and Chrome to make sure your code (locator and such) is correct. Then a couple solutions you might want to try on IE.

  • Focus on the element before clicking.
ecrButton.click(); // dummy click to focus
// or ecrButton.sendKeys("\n"); // also tries to focus
ecrButton.click(); // do your actual click
  • Use click method from Actions class.
new Actions(driver).click(ecrButton).perform();
  • Inject JavaScript clicking
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ecrButton);
Sign up to request clarification or add additional context in comments.

1 Comment

You must have answered right before me. I am marking yours as the correct answer since it contains the javascript technique that worked for me. Thanks.
0

Found this question and it contained the answer that worked for me.

((JavascriptExecutor) driver).executeScript("arguments[0].click()", ecrButton);

There seems to be some sort of bug in the IEDriverServer that doesn't allow you to click on some inputs. Using javascript instead seems to work well.

*Much appreciation to @KrishPrabakar

Comments

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.