Cannot click Submit Button

34 views
Skip to first unread message

Small World

unread,
Jun 30, 2020, 1:33:35 AM6/30/20
to Selenium Users
There are five Dialog boxes and each Dialog box has the same code for the Submit Button except the value changes for "id" and "onclick".
A single Dialog box has five question and when one answer for each question is selected the Submit button gets enabled.

Code before button gets Enabled
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<div class="modal-footer">
                                    <input type="button" id="3118" class="btn btn-danger RejectionModal" value="Decline">
                                    <input type="button" id="btnSubmit_3118" disabled="disabled" style="opacity: 0.5;" onclick="submitObservation(3118,653);" class="btn btn-primary review-submission" value="Submit">

                                </div>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Code after button gets Enabled
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<div class="modal-footer">
                                    <input type="button" id="3118" class="btn btn-danger RejectionModal" value="Decline">
                                    <input type="button" id="btnSubmit_3118" style="opacity: 1;" onclick="submitObservation(3118,653);" class="btn btn-primary review-submission" value="Submit">

                                </div>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


The code which I used to click the Submit button 

JavascriptExecutor executor1 = (JavascriptExecutor)driver;

 WebElement element1 = driver.findElement(By.xpath("//*[contains(@class,'btn btn-primary review-submission') and contains(@style,'opacity: 1;')]"));
  
 executor1.executeScript("arguments[0].click();", element1); 


The above code works fine for the First Submit button but not for the rest.

The exception that throws is :               
org.openqa.selenium.NoSuchElementException: Unable to locate element: //*[contains(@class,'btn btn-primary review-submission') and contains(@style,'opacity: 1;')]

Thanks & Regards,
Small World

naveen kumar

unread,
Jun 30, 2020, 2:45:04 AM6/30/20
to seleniu...@googlegroups.com
 and contains(@style,'opacity: 1;')]") remove this line and excute only with xpath.
Also, give some delay time after loading the URL for loading the full page.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/e09b2a62-b5f7-4e7f-9909-5a69fc011c73o%40googlegroups.com.

Adrian

unread,
Jul 1, 2020, 6:40:46 PM7/1/20
to Selenium Users
HI,
Try driver.findElement(By.cssSelector("input[id^='btnSubmit']"))
This will find the button with the id that starts with btnSubmit

Regards,
Adrian.
Reply all
Reply to author
Forward
0 new messages