How can i create xpath below this code - html

I am trying to create xpath this (Unscheduled Visitor Check-In) button. i am unable to find the button name or id. can anyone help me out from this issue please. will appreciate that. please see the attachment.
<div id="SAFEControl307369" class="buttontextactivestyle" uniquefieldid="307369" onselectstart="return false" onchange="setAttribute('IsModified','1');" onclick=" document.body.style.cursor = 'wait'; window.location.href = 'QSForm.aspx?FormID=194&Hidden=1';return false;" datatype="" boundcolumn="" ismodified="0" style="position:absolute;left:280px;top:5px;height:0px;width:250px; ;" caption="" tabindex="-1">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr style="height:20px;cursor:pointer;">
<td class="buttonleftactivestyle"/>
<td class="buttonmiddleactivestyle" align="center">
<div>Unscheduled Visitor Check-In</div>
[Screenshot of the application with xpath][1]

IWebElement element = driver.FindElement(By.XPath("//div[#id='SAFEControl307369']/table/tbody/div"));
When you checking the element you need look on the try for create the XPath.

Please use below xpath:
//div[contains(.,'Unscheduled Visitor Check-In')]
You can try the code below:
WebElement element= driver.findElement(By.xpath("Your XPath"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);
Feel free to change the locator in the code above. Try to with xpath provided by the firepath as shown in image.

Related

Click on Hyperlink for TD Object

I want to click on a hyperlink on a webpage using VBA that I have found using the below method:
Set trs = ie.document.getElementsByTagName("tr")
For Each trObj In trs
Set tds = trObj.getElementsByTagName("td")
For Each tdObj In tds
If tdObj.className = "btn_container" And tdObj.innerText = "Reinstate Award" Then
tdObj.Click
End If
Next
Next
I can't get the tdObj.Click bit to click the hyperlink.
The html is below:
<td class="btn_container">
<input name="_linkSubmit" type="hidden"><a name="assessment_Reinstate" class="button_link" id="assessment_Reinstate" onclick="javascript:return disableLinks(this.href);" href='javascript:submitLink(document.Form0,"assessment_Reinstate");' type="button" renderer="uk.co.slc.tapestry.link.PortalLinkRenderer#1a79ffb">Reinstate Award</a>
</td>
Any help would be greatly appreciated.
Thanks
Jim
You can try using the link id
ie.document.querySelector("#assessment_Reinstate").click

Click the second button of an img in VBA

I'm trying to click an imagebutton on IE by using getAttribute("src"), but there are to identical buttons with the same src-code, so when I use this code, it clicks the first and I want to click the second. Can somebody help me?
I'm thinking of creating a loop to search through and choose the second one, but I have no idea how to write the code! Can somebody help me out?
This is the code I use to click the first button:
Set allInputs = IE.Document.getElementsByTagName("img")
For Each Element In allInputs
If Element.getAttribute("src") = "/forms/Content/Images/0006.gif" Then
Element.Click
Exit For
End If
Next Element
The HTML code for the buttons are:
<tr class="jqgfirstrow" role="row"
<tr tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr" id="1" role="row"
< img src="/forms/Content/Images/0006.gif"
<tr tabindex="-1" class="ui-widget-content jqgrow ui-row-ltr" id="2" role="row
< img src="/forms/Content/Images/0006.gif"
Thanks for all of your help!
I did it with code here:
Set allInputs = IE.Document.getElementsByTagName("img")
allInputs(2).click

Can I make HTTP POST request from Thymeleaf table in Spring Boot application

I have a Thymeleaf template in a simple Spring Boot application. The template contains a list in a table as follows:
<p>There are <span th:text="${#lists.size(persons)}"></span> people:</p>
<table th:if="${not #lists.isEmpty(persons)}" border="1">
<tr>
<th>ID</th>
<th>Name</th>
<th>Address</th>
<th>Telephone</th>
<th>Email</th>
<th>Actions</th>
</tr>
<tr th:each="person : ${persons}">
<td th:text="${person.personId}"></td>
<td th:text="${person.name}"></td>
<td th:text="${person.address}"></td>
<td th:text="${person.telephone}"></td>
<td th:text="${person.email}"></td>
<td>
Edit |
Delete
</td>
</tr>
</table>
I want to enable edit and delete functionality as per the last cell in the table. But at the moment both requests are for HTTP GET. That is fine for edit where a person's details are fetched from the server for editing, but delete should trigger a POST request because of the data changes on the server.
Does anyone know if Thymeleaf allow a POST request per row of a table? Or do I have to write a simple HTML form per row?
The GET form is currently:
<td>
Edit
<!--a href="#" data-th-href="#{/delete(personId=${person.personId})}">Delete</a></td-->
<form method="get" th:action="#{/edit(personId=${person.personId})}">
<button type="submit" name="submit" value="value">Edit</button>
</form>
</td>
Where I have a link and a form for testing.
The controller method to be called is:
// Gets a Person.
#RequestMapping(value="/edit", method=RequestMethod.GET)
public String getEditPerson(#RequestParam("personId") String personId, Model model) {
logger.info(PersonController.class.getName() + ".getEditPerson() method called.");
Person person = personDAO.get(Integer.parseInt(personId));
model.addAttribute("person", person);
// Set view.
return "/edit";
}
The error when the button version of GET is called is:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sun Jul 24 00:26:16 BST 2016
There was an unexpected error (type=Bad Request, status=400).
Required String parameter 'personId' is not present`
I am using GET to trigger editing because no data is sent to the server here other than the personId. No database action is taken so it should be a GET.
you are using Links and I don't think that is possible, you would need to use a form where you can specify the method POST to be used.
In the example below im using a <button> instead of a <a> element, but it will work, the only thing you need to do is to style your button with CSS to look like your links
<form method="POST" th:action="#{/edit(personId=${person.personId})}">
<button type="submit" name="submit" value="value" class="link-button">This is a link that sends a POST request</button>
</form>
now in your code should look like this
<tr th:each="person : ${persons}">
<td th:text="${person.personId}"></td>
<td th:text="${person.name}"></td>
<td th:text="${person.address}"></td>
<td th:text="${person.telephone}"></td>
<td th:text="${person.email}"></td>
<td>
<form method="POST" th:action="#{/edit(personId=${person.personId})}">
<button type="submit" name="submit" value="value" class="link-button">EDIT</button>
</form> |
<form method="POST" th:action="#{/delete(personId=${person.personId})}">
<button type="submit" name="submit" value="value" class="link-button">DELETE</button>
</form>
</td>
</tr>
EDIT
As you just shared you Java code, in the controller you are expecting the personId not as a PathVariable, but as a RequestParam,
in that case your form should have that value...
edit your form and add the person id as follows.
<form method="POST" th:action="#{/edit}">
<input type="hidden" name="personid" id="personId" th:value="${person.personId}" />
<button type="submit" name="submit" value="value" class="link-button">This is a link that sends a POST request</button>
</form>
Notice also I changed the action of the form to be just /edit, as its what your controller looks like
Does anyone know if Thymeleaf allow a POST request per row of a table? Or do I have to write a simple HTML form per row?
HTML doesn't support POST request with links and you have to use forms (as Rayweb_on explained). But Thymeleaf allows you to define custom tags which helps a lot :
<a th:href="#{/edit(personId=${person.personId})}" custom:linkMethod="post">Edit</a>
... which would generate following HTML (assuming jQuery is available) :
Edit
Custom tag definition (without error checking to keep it simple) :
/**
* Custom attribute processor that allows to specify which method (get or post) is used on a standard link.
*/
public class LinkMethodAttrProcessor extends AbstractAttributeTagProcessor {
private static final String ATTR_NAME = "linkMethod";
private static final int PRECEDENCE = 10000;
public LinkMethodAttrProcessor(final String dialectPrefix) {
super(
TemplateMode.HTML, // This processor will apply only to HTML mode
dialectPrefix, // Prefix to be applied to name for matching
null, // No tag name: match any tag name
false, // No prefix to be applied to tag name
ATTR_NAME, // Name of the attribute that will be matched
true, // Apply dialect prefix to attribute name
PRECEDENCE, // Precedence (inside dialect's own precedence)
true); // Remove the matched attribute afterwards
}
#Override
protected void doProcess(final ITemplateContext context, final IProcessableElementTag tag,
final AttributeName attributeName, final String attributeValue,
final IElementTagStructureHandler structureHandler) {
// get the method name (tag parameter)
final IEngineConfiguration configuration = context.getConfiguration();
final IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration);
final IStandardExpression expression = parser.parseExpression(context, attributeValue);
final String method = (String) expression.execute(context);
// add custom javascript to change link method
final String link = tag.getAttribute("href").getValue();
final String action = "$('<form action="" + link + "" method="" + method + ""></form>').appendTo('body').submit(); return false;";
structureHandler.setAttribute("onclick", action);
structureHandler.setAttribute("href", "#");
}
}
See the Thymelead documentation for example of how this custom attribute needs to be registered.

Find element by xpath selenium web driver

I have a webpage:
<div class="formfonttitle">Wireless - General</div>
<div style="margin-left:5px;margin-top:10px;margin-bottom:10px"><img src="/images/New_ui/export/line_export.png"></div>
<div class="formfontdesc">Set up the wireless related information below.</div>
<table width="99%" border="1" align="center" cellpadding="4" cellspacing="0" id="WLgeneral" class="FormTable">
<tr id="wl_unit_field">
<th>Frequency</th>
<td>
<select name="wl_unit" class="input_option" onChange="_change_wl_unit(this.value);">
<option class="content_input_fd" value="0" >2.4GHz</option>
<option class="content_input_fd" value="1" selected>5GHz</option>
</select>
</td>
</tr>
I am trying to select "2.4GHz" using xpath. By default "5GHz" option is selected. I am doing this from Python script and using selenium webdriver.
I am doing this:
elements = mydriver.find_element_by_xpath("//div[#class='wl_unit']")
title = elements[1].find_elements_by_xpath(".//div[#class='content_input_fd']")
but it's not working.
You can use the following XPath to find the 2.4GHz option element, and then peform 'click' on the element to get it selected :
option = mydriver.find_element_by_xpath("//select[#name='wl_unit']/option[#value='0']")
option.click()
You can do this by running JavaScript with selinum like this
mydriver.execute_script("$('.input_option option[value="0"]')")
This may also help you for selecting an option in python selenium.
#Manoj
It is under select, so you can use select method which is generally used for dropdown as follows:
You wrote this.
Webelement elements = mydriver.find_element_by_xpath("//div[#class='wl_unit']")
Now continue :
Select object = new Select(elements);
object.selectByValue(1);
or
object.selectByVisibleText("5GHz")
Hope this will help you..
Try Following code
WebElement wlUnit= WebElement elea= driver.findElement(By.name("wl_unit"));
Select wlSelect = new Select(wlUnit);
wlSelect.selectByValue(0);
OR
WebElement wlUnit= WebElement elea= driver.findElement(By.name("wl_unit"));
Select wlSelect = new Select(wlUnit);
wlSelect.selectByVisibleText("2.4GHz");

send data from table to another page into forms

I have a table in "clients.html" that contains clients data,when I clic on one of those clients then the "create Document" I want to send the data of this clients to the new page "Doc.html",this is my code:
clients.html
<div class="btn-group" style="
right: 5px;
" ng-repeat="post in posts">
<div class="btn btn-icon">
<a ui-sref="app.deviscl({customerID:post.id})" data-toggle="tooltip" title="create Doc"><img src="img\facturejj.png"
class="m-b-xs w-xs"> </a>
</div></div>
this is the routing:
.state('app.deviscl', {
url: '/devis/ajout/:customerID',
templateUrl: 'tpl/deviscl.html',
controller: 'editController'
})
but in the clients.html the button create Doc appears many times,If I try to remove ng-repeat from the div of the button I can't get any result
thanks a lot for help
Basicly with this code you are creating a button for every post in posts. I am guessing you want 1 button, but somehow that 1 button knows which post in posts is selected?
In that case you can create a form with a select dropdown, then they pick a 'post in posts' from the select and then submit the form, which links them to the create doc page with the right data?
UPDATE
Example as requested:
<form>
<table>
<tr>
<td>
<select ng-model="postId" ng-options="post.id as post for post in posts"></select>
</td>
</tr>
<tr>
<td><input type="submit" ng-click="createDoc(postId) value="save" /></td>
</tr>
</table>
</form>
Ofcourse you can alter this simple form to be applicable for your own app. e.g add css or change some names etc.
and then in your controller:
$scope.createDoc = function(postId) {
app.deviscl({customerID:postId});
}
and your routing remains the same.