0

I am automating Peoplesoft through Selenium. Web driver is able to locate the web element:

System.println.out(driver.findElements(By.id("Element_id").getAttribute("name"));

Web driver prints the name attribute of that element, but when I am trying to click it fails:

driver.findElements(By.id("Element_id").click();

although it does not throw error message, and the web driver remain in running status, without terminating itself.

Please help.

2 Answers 2

2

There are a couple of explanations. The most common one is that the element that is identified is actually a different element than you expected to identify. It's less common with id's which should be unique, but it can happen still if a dev accidentally gives multiple elements on a page the same ID, or if there is something duplicating an element and the logic doesn't exist to update the ID for each duplicate element.

Another explanation could be that the element you found is not the element that is expected to be clicked. Maybe it is a child (or in rarer cases a parent or sibling) of the element that is actually receiving the click events. Try clicking on the parent or ancestor element.

Another explanation could be that Selenium is performing the click, but the element is actually expecting some event to be fired that Selenium's "click" doesn't trigger. Maybe you have to hover over the element first and then click? Maybe it's something more cryptic like expecting a non-standard event?

Hopefully it's one of these explanations, if not let me know and maybe we can troubleshoot further.

2
  • Explanations are quite helpful ,but the same web element web driver is able to click ,when we are simply opening that web page and doing click operation, but when i am trying to do some other operations like , sending keys to certain web elemets on the same page ,selecting some values from look up values etc., the web driver is not able to click in such case.
    – saurav
    Sep 15, 2013 at 14:05
  • Then it sounds like you are almost for sure hitting the first case. The other operations must be adding an additional element with the same id somewhere else on the page. In this case, you need to identify the element in some other way. CSS Selector or XPath can be used to be more specific about what the parent/ancestor elements are as well.
    – Sam Woods
    Sep 15, 2013 at 15:44
0

Try using SendKeys

driver.findElements(By.id("Element_id").SendKeys("\n");
2
  • Hi, Brandon. Would sending a newline character necessarily work to simulate a click action? I find it difficult to accept that this would work for, for instance, selecting a radio button.
    – Kate Paulk
    Sep 16, 2013 at 12:00
  • You're correct, there are limited use cases. In my personal experience, I've had success using this method on standard links, buttons, and "entering" off of form fields in IE-based tests.
    – brandon
    Sep 22, 2013 at 1:42

Your Answer

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

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