I'm working an OpenBravo application. I'm facing a problem with clicking an element when tried with a text id class. I'm able to find the element but the element is not clicking on that button.
I used the click() event with the action sendKeys() in JavaScript but it is still not working.
driver.findElement(By.id("terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_okButton")).click();
Html format is
<div id="terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_control">
<input style="width: 100%;margin-bottom:0px;background-color: #E8E8E8;width:300px" readonly="readonly" class="enyo-input input" id="terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_EmployeeName" type="text" value="Kanika Sachdeva">
<br id="terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_control2">
<input style="width: 100%;margin-bottom:0px;width:300px" maxlength="15" class="enyo-input input" id="terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_EMPLOYEEID" placeholder="Enter Employee Id ..." type="text">
<br id="terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_control3">
<button class="enyo-tool-decorator btnlink btnlink-gray modal-dialog-button" id="terminal_containerWindow_pointOfSale_DWCRM_UI_EmployeeIdPopup_bodyButtons_okButton">OK</button>
</div>
Related
So I want to target a textbox that appears in a list that comes after the label "First Name" and send a first name to the box, but can't seem to be able to target the textBox...
What I've tried:
WebElement firstNameLocTry = driver.findElement(By.xpath("//label[text()='First Name']/following-sibling::div"));
firstNameLocTry.sendKeys(firstName);
What the li look like:
<li class="WPTO WKVO" role="presentation" data-automation-id="formLabelRequired">
<div class="WBUO WETO WDUO">
<label id="56$551056--uid24-formLabel" data-automation-id="formLabel" for="56$551056--uid24-input">First Name</label>
<div class="WEUO wd-c8594868-6b31-4526-9dda-7d146648964b" aria-hidden="true">First Name</div>
</div>
<div data-automation-id="decorationWrapper" id="56$551056" class="WFUO">
<div class="WICJ">
<div class="WMP2 textInput WLP2 WJ5" data-automation-id="textInput" id="56$551056--uid24" data-metadata-id="56$551056" style="visibility: visible;">
<input type="text" class="gwt-TextBox WEQ2" data-automation-id="textInputBox" tabindex="0" role="textbox" id="56$551056--uid24-input" aria-invalid="false" aria-required="true">
</div>
</div>
</div>
</li>
Any reason my sendKeys just leads to Element not interactable?
The attached HTML code Produce below out put
With the given XPath points to the second "First Name" Div [below pic], when you perform sendKeys, it is obvious that the error "Element not interactable" will be thrown.
Try with below two Xpaths,
1. //label[text()='First Name']//parent::div/following-sibling::div
2. //label[text()='First Name']//parent::div/following-sibling::div//input
Please use following xpath:
//div[text()='First Name']
or try:
//*[contains(text(),'First Name')]
This is my first on posting here. I hope you understand my question!
<script language="JavaScript">
function setVisibility(id, visibility)
{
document.getElementById(id).style.display = visibility;
}
</script>
<% for(cart c: cart) {%>
<td> ......</td>
<td> ......</td>
<td> ......</td>
<td> ......</td>
<td>
<input type=button name=type value='Edit' onclick="setVisibility('DivQTY', 'inline');">
<div id="DivQTY" style="display: none">
<input type="text" name="qty">
<form action="doEditCart.jsp?id=<%= c.getID() %>" method="post">
<input type="submit" value="Save">
</form>
</div>
</td>
<% }%>
This Shows a table and, in every row, shows a "Edit" button.
My problem here is that, if i press any "Edit" button in any row, "TextBox" and "Save" button appears only in the first row.
In this capture I pressed Edit in the fourth row.
How to show TextBox and Save button in the row that I pressed the edit button?
Thank you.
Your for statement is creating different <div> elements with the same id attribute, what is not allowed.
As a solution, you could use the cart's id (c.getID()) as part of the div's id:
(...)
<input type=button name=type value='Edit' onclick="setVisibility('DivQTY<%=c.getID()%>', 'inline');">
<div id="DivQTY<%=c.getID()%>" style="display: none">
(...)
The problem is at below line where you are using same id for each div
<div id="DivQTY" style="display: none">
Element IDs should be unique within the entire document. Use different dynamic IDs for each element in HTML.
HTML 4.01 specification says ID must be document-wide unique.
Read more about it here Two HTML elements with same id attribute: How bad is it really?
I am trying to click on Button, but not able to click due to having same xpath's for all buttons on the webpage.
There are Questions with Yes and No option button. I want to identify the button with question.
All the Yes button are of same XPATH and all the No buttons are of same xpath.
Below is the HTML code to click on "Yes" button :
<div id="answerContainer_id" class="right two answerContainer">
<input id="validation_question_3_13" type="hidden" value="required"
name="validation_question_3_13"/>
<div class="answer questionAnsleft selected">
<input id="answer_3_13_1" type="radio" value="1" name="Q13" style="display:none;"/>
<div class="questionAnsRight">
Yes </div>
</div>
<div class="answer questionAnsleft disabled">
</div>
</div>
<div id="question_3_14" class="">
<input type="hidden" name="questionIds[]" value="14"/>
<div class="left" style="width: 680px;">
<div id="answerContainer_id" class="right two answerContainer">
<input id="validation_question_3_14" type="hidden" value="required"
name="validation_question_3_14"/>
<div class="answer questionAnsleft selected">
<input id="answer_3_14_1" type="radio" value="1" name="Q14" style="display:none;"/>
<div class="questionAnsRight">
Yes </div>
</div>
I dont even know how many questions are there in your page.. But as per your HTML source, there are two questions and two yes buttons. You can use the xpath as (xpath=//div[#class='questionAnsRight'])[1].
If you need to click more number of Yes buttons, iterate it with (xpath=//div[#class='questionAnsRight'])[i].
You can bind button to answer input
For first button css
#answer_3_13_1+div
For second
#answer_3_14_1+div
Or use name
[name=Q13]+div
[name=Q14]+div
I'm trying to render a few radiobuttons in a Struts2 web application.
The value of each radiobutton is an integer and its associated label should be an i18n text, which varies as a function of the value. The i18n keys have the form Common.eventTypeId.<<integer value>>, (e.g. Common.eventTypeId.28, Common.eventTypeId.29, etc).
However when I access the page the labels don't get translated as there are wrong keys: Common.eventTypeId.null. What puzzles me is that the same variable used to build the i18n key renders ok as the value of the radio button.
Here is the snippet where the HTML code is generated. eventTypeIds is a List<Integer> containing 3 elements: 28, 29 and 31.
<s:iterator value="eventTypeIds" var="eTypeId">
<div class="frm-field">
<s:set var="label" value="%{getText('Common.eventTypeId.' + eTypeId )}"/>
<s:radio name="currentActivity.eventTypeId" list="eTypeId" listValue="label"/>
</div>
</s:iterator>
The relevant i18n keys:
Common.eventTypeId.29 = CAA
Common.eventTypeId.28 = Practical
Common.eventTypeId.31 = Non-assessable activity
This is the actual HTML being generated right now:
<div class="frm-field">
<input type="radio" value="29" checked="checked" id="frm-activity_currentActivity_eventTypeId29" name="currentActivity.eventTypeId">
<label for="frm-activity_currentActivity_eventTypeId29">Common.eventTypeId.null</label>
</div>
<div class="frm-field">
<input type="radio" value="28" id="frm-activity_currentActivity_eventTypeId28" name="currentActivity.eventTypeId">
<label for="frm-activity_currentActivity_eventTypeId28">Common.eventTypeId.null</label>
</div>
<div class="frm-field">
<input type="radio" value="31" id="frm-activity_currentActivity_eventTypeId31" name="currentActivity.eventTypeId">
<label for="frm-activity_currentActivity_eventTypeId31">Common.eventTypeId.null</label>
</div>
This would be the expected HTML:
<div class="frm-field">
<input type="radio" value="29" checked="checked" id="frm-activity_currentActivity_eventTypeId29" name="currentActivity.eventTypeId">
<label for="frm-activity_currentActivity_eventTypeId29">CAA</label>
</div>
<div class="frm-field">
<input type="radio" value="28" id="frm-activity_currentActivity_eventTypeId28" name="currentActivity.eventTypeId">
<label for="frm-activity_currentActivity_eventTypeId28">Practical</label>
</div>
<div class="frm-field">
<input type="radio" value="31" id="frm-activity_currentActivity_eventTypeId31" name="currentActivity.eventTypeId">
<label for="frm-activity_currentActivity_eventTypeId31">Non-assessable activity</label>
</div>
Note that the integer values are being correctly displayed using eTypeId variable, but that variable is null when building the i18n key. What am I missing? Did I misunderstand the s:radio tag usage?
You are missing # before using eTypeId var inside <s:set> tag.
<s:set var="label" value="%{getText('Common.eventTypeId.' + #eTypeId )}"/>
BTW <s:radio> takes iterable source in list attribute, so you can use your eventTypeIds list inside radio tag and get translated text with listValue attribute and top keyword.
<s:radio name="currentActivity.eventTypeId" list="eventTypeIds"
listValue="%{getText('Common.eventTypeId.' + top)}"/>
in my jsp, when i navigate through tab key it skips my Save and Reset button. and move to next component in my page. even though i have not used tabindex in my jsp files. please suggest what could be the reason. thanks
code is like:
<div>
<input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}"/>
<input type="submit" class="button" name="_eventId_search" value="Search"/>
<span class="save_button_common" onClick="submitForm('save')">Save</span>
<span class="reset_button_common" onClick="submitForm('reset')">Reset</span>
</div>
May be because it is not input type , you can explicitly try setting tabIndex
Try:
<div>
<input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}"/>
<input type="submit" class="button" name="_eventId_search" value="Search"/>
<input type="button" class="save_button_common" onClick="submitForm('save')">Save</input>
<input type="button" class="reset_button_common" onClick="submitForm('reset')">Reset></input>
</div>
Note if it's a form you need input type="button" rather than just using <button> which you can otherwise just for straight links that don't submit a form. This is particularly relevant with Internet Explorer that treats the button tag somewhat differently to other browsers (submitting the "value=" rather than the enclosed text or something like that)