2

I am trying to click on one of the hidden values but it is neither fetching nor it clicking on that value. I am trying for Indian railways berth availability wherein I want the source station value e.g. LUCKNOW ALAMBGH- AMV to get fetched and should accept that value.

What code can I write for accepting the value?

2 Answers 2

3

You can't click hidden elements with Selenium. However, you can trigger the click through Javascript, as found on SO:

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", element);
5
  • 1
    +1 for this clever trick. But whole point of browser automation, like Selenium, is to do what user can do, and have exactly same result as if user did it. If user cannot click on a hidden element, why it would make sense to allow Selenium to do it? OP is trying to do something strange. Commented Mar 8, 2016 at 15:03
  • @PeterMasiar in the link posted in the answer, there is comment that says "overflow: hidden doesn't necessarily mean that it is hidden"
    – ilm
    Commented Mar 8, 2016 at 17:32
  • I assume it will be hidden for the human user (no way to access it by clicking), but accessible via JS trickery like FDM's. It depends how you define "hidden" I guess. My definition is anthropocentric. :-) Commented Mar 8, 2016 at 17:43
  • Can you tell me how it will click on the partial value e.g. LUCKNOW instead of the whole value. Commented Mar 17, 2016 at 10:28
  • Change the selector for the webelement
    – FDM
    Commented Mar 17, 2016 at 11:03
0

Simple way & working solution, When you want to take action on Hidden element

  1. First of all we know that element should be visible

    hidden_element.send_keys ""
    
  2. Once element get visible using selenium we can easily take any action

    hidden_element.click()
    

I hope code snippet will help you! Try it

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.