0

I am trying to click on a search button that is hidden. I tried few methods but it didn't work:

<form id="form1" name="viewClient" method="post" action="ClientMgmtServlet" abframeid="iframe.0.10752026348407184" abineguid="027BBB6AD3324EFDA3FED3803F068951">
<input type="hidden" value="U7dPiPXFQhCDtDaTHAVH" name="preventionflag"/>
<input id="searchClientBtn" type="hidden" value="Search" name="searchClientBtn"/>

I used this method:

//Enter client ID
String userid = prop.getProperty(CLIENTID);
driver.findElement(By.id("clientId")).sendKeys(userid);

//Enter client name
String clientName = prop.getProperty(CLIENTNAME);
driver.findElement(By.id("clientName")).sendKeys(clientName);

//enter Mobile No
String mobile_no = prop.getProperty(MOBILE_NO);
driver.findElement(By.id("mobileNo")).sendKeys(mobile_no);
WebElement elem = driver.findElement(By.xpath(".//*[@id='searchClientBtn']"));
String js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible';";

((JavascriptExecutor) driver).executeScript(js, elem);

It was clicking on the search button but the data I have entered in the fields were not accepting. It worked like I haven't input the data only. That showed me all the users in the search.

Can someone help me with this problem?

Brian
  • 14,610
  • 7
  • 35
  • 43
avisek
  • 3
  • 3

4 Answers4

1

You can check this - How to click on hidden element in Selenium WebDriver?

Also it is not a good idea to use xpath for finding elements, if you can change it.

Note that some versions of the browsers (i think - FF 34.xx.x, 35.xx.x) had this weird problem with the js execution.

Community
  • 1
  • 1
Tony
  • 72
  • 1
  • 8
  • 1
    `not a good idea to use xpath for finding elements` - I would not give such advice. It doesn't make sense. Please explain. – alecxe Apr 03 '15 at 16:40
  • @Антоний Кунчев I didnt try exactly that but something like that.. You can see in my code. in the last part. But it didnt help. – avisek Apr 04 '15 at 11:40
  • Please expand on why we should not use Xpath – Robbie Wareham Apr 05 '15 at 11:23
  • It is a good practice to use CSS over Xpath. They are faster, more readable and easier to maintain. Little research for "good practice" how to use selectors will give you all the answers. Also you can check this - http://stackoverflow.com/questions/16788310/what-is-the-difference-between-css-selector-xpath-which-is-betteraccording-t – Tony Apr 08 '15 at 12:42
0

The input-element with id searchClientBtn is a hidden field. You can not interact with it in a normal browser. As Selenium is just driving a browser, it won't let you do things you cannot do in a normal browser.

This is normal behavior and you cannot change it.

To submit your form, you can call the click() method on any visible input field in that form. You can also grab the form element and click() on that.

Stefaan Neyts
  • 2,054
  • 1
  • 16
  • 25
0

As @Stefaan Neyts explained try to submit the form. Try below code after filling all the details in the form.

driver.findElement(By.id("clientName")).submit();
Vish Shady
  • 327
  • 1
  • 5
  • 15
0

I found out the problem which I was having. I had two element with the same id "searchClientBtn". So i used this driver.findElement(By.xpath("(.//*[@id='searchClientBtn'])[2]")).click(); Which let me read the second element which was not hidden an it solved my problem. Thanks to everyone.

avisek
  • 3
  • 3