watir webdriver unable to click button in the table - watir

<tr class="even_row">
<td colspan="1" rowspan="1">
<button type="button" onclick="doSubmit('_eventId_addToHouseholdFromOther')">
<span>
<i class="icon-arrow-left"></i>
</span>
</button>
</td>
<td colspan="1" rowspan="1"> … </td>
<td colspan="1" rowspan="1"> … </td>
<td colspan="1" rowspan="1"> … </td>
</tr>
Does anybody know, how I can click on this button using watir webdriver?

Assuming that the <i class="icon-arrow-left"> element is unique (ie no other i element with the same class exists), you can do:
browser.i(:class => 'icon-arrow-left').click

Related

Selenium Python select and click multiple checkbox elements by input type

Trying to select and click multiple checkboxes on a page. they don't have a class, ID or names that match. All they have in common is their input type (checkbox). I'm able to select individual checkboxes using XPATH but its not practical as there's at least 100 checkboxes on the page.
Here's a section of the HTML. I've been testing this code on an off-line version of the site.
<body>
<tbody>
<tr>
<td class="borderBot"><b>Activity</b></td>
<td class="borderBot">
<table cellpadding="3" cellspacing="3" width="100%">
<tbody>
<tr>
<td width="33%">
<input type="checkbox" name="competency1Activity" value="1" />
Plan (ie Interpreted diag etc)
</td>
<td width="33%">
<input type="checkbox" name="competency1Activity" value="2" />
Carry Out (ie conducted work)
</td>
<td width="33%">
<input type="checkbox" name="competency1Activity" value="4" />
Complete (ie Compliance etc)
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="borderBot"><b>Supervision</b></td>
<td class="borderBot">
<table cellpadding="3" cellspacing="3" width="100%">
<tbody>
<tr>
<td width="33%">
<input
type="checkbox"
name="competency1Supervision"
value="1"
/>
Direct
</td>
<td width="33%">
<input
type="checkbox"
name="competency1Supervision"
value="2"
/>
General
</td>
<td width="33%">
<input
type="checkbox"
name="competency1Supervision"
value="4"
/>
Broad
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="borderBot"><b>Support</b></td>
<td class="borderBot">
<table cellpadding="3" cellspacing="3" width="100%">
<tbody>
<tr>
<td width="33%">
<input type="checkbox" name="competency1Support" value="1" />
Constant
</td>
<td width="33%">
<input type="checkbox" name="competency1Support" value="2" />
Intermittent
</td>
<td width="33%">
<input type="checkbox" name="competency1Support" value="4" />
Minimal
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="borderBot"><b>Materials</b></td>
<td class="borderBot">
<table cellpadding="3" cellspacing="3" width="100%">
<tbody>
<tr>
<td width="50%">
<input type="checkbox" name="competency1Extended" value="1" />
Insulation failure
</td>
<td width="50%">
<input type="checkbox" name="competency1Extended" value="2" />
Incorrect connections
</td>
</tr>
<tr>
<td width="50%">
<input type="checkbox" name="competency1Extended" value="4" />
Circuits-wiring; eg. open short
</td>
<td width="50%">
<input type="checkbox" name="competency1Extended" value="8" />
Unsafe condition
</td>
</tr>
<tr>
<td width="50%">
<input
type="checkbox"
name="competency1Extended"
value="16"
/>
Apparatus/component failure
</td>
<td width="50%">
<input
type="checkbox"
name="competency1Extended"
value="32"
/>
Related mechanical failure
</td>
</tr>
<tr>
<td width="50%">
<input
type="checkbox"
name="competency1Extended"
value="64"
/>
Read/interpret drawings/plans
</td>
<td width="50%">
<input
type="checkbox"
name="competency1Extended"
value="128"
/>
Other elec app and circuit faults
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<input
type="hidden"
id="competency1ExtendedCount"
name="competency1ExtendedCount"
value="8"
/>
</tbody>
</body>
Try 1 - this selects and clicks the first checkbox but none of the others
checkboxes = driver.find_element(By.CSS_SELECTOR, "input[type='checkbox']").click()
Try 2 - Thought this would work but I cant get the syntax right
checkboxes = driver.find_element(By.CSS_SELECTOR, "input[type='checkbox']")
for checkbox in checkboxes:
checkboxes.click()
time.sleep(.3)
Try 3 - able to select first checkbox (of 3) with this name
checkboxes = driver.find_element("name", "competency1Ativity").click()
find_element() will return only the first matching element, where as you need to identify all of them. So you need to use find_elements() method.
Solution
You can identify all the checkbox and store the elements within a list and then click on them one by one using either of the following locator strategies:
Using CSS_SELECTOR:
from selenium.webdriver.common.by import By
checkboxes = driver.find_elements(By.CSS_SELECTOR, "td input[type='checkbox']")
for checkbox in checkboxes:
checkbox.click()
Using XPATH:
from selenium.webdriver.common.by import By
checkboxes = driver.find_elements(By.XPATH, "//td//input[#type='checkbox']")
for checkbox in checkboxes:
checkbox.click()
Your option 2 was nearly correct, however it should have been find_elements() not find_element()
Since find_element() just returns an webelement where as find_elements() returns list of elements.
code:
checkboxes = driver.find_elements(By.CSS_SELECTOR, "input[type='checkbox']")
for checkbox in checkboxes:
checkbox.click()
time.sleep(0.5)

Find label name which doesn't contain input immediately from a table

I am having a table which contains multiple td/tr.
My problem is label which i want to get doesn't contains input immediately neither that label has any attributes property.
I want to get "Countries of Permanent Residence" and Dates which are in span but doesn't have any properties that span is in div that too doesn't contains any property.
I tried with
formElement[input[name="icims_gh_Permanent_Country_Residence"]]
But don't know how to get associate label.
Html looks like:
<div style="margin:0px">
<table style="width:100%" border="1" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td valign="top">
<div style="margin:0px">
<span style="font-family:arial,helvetica,sans-serif;font-size:12px"> Countries of Permanent Residence (list all) </span>
</div>
</td>
<td valign="top">
<div style="margin:0px">
<span style="font-family:arial,helvetica,sans-serif;font-size:12px"> Dates </span>
</div>
</td>
</tr>
<tr>
<td colspan="2" valign="top">
<div style="margin:0px">
<div>
<input type="hidden" name="icims_gh_Permanent_Country_Residence" value="1">
<a name="0.1_icims_ga_Permanent_Country_Residence"></a>
<div>
<table style="width:100%;border:0px">
<tbody>
<tr>
<td>
<table style="width:100%" border="1" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td valign="top">
<div style="margin:0px">
<span style="font-family:arial,helvetica,sans-serif;font-size:12px">
<input type="text" name="icims_0_permResidenceCountry"> </span>
</div>
</td>
<td valign="top">
<div style="margin:0px">
<span style="font-family:arial,helvetica,sans-serif;font-size:12px">
<input type="text" name="icims_0_permResidenceCountryDates"> </span>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>

How to send XML reponse to groovy script in SoapUI

Referring to this previous question:
How to access the attribute value of soap UI response XML
I need this script to be dynamic, be able each test run to send a different XML body to parse.
How can this be achieved?
Sample XML
</script>
<form onsubmit="submitAction();return false;" name="submitForm" method="post" action="auth_vbv_browser_authentication.xsl">
<input value="auth_vbv_browser_authentication.xsl" type="hidden" name="AA_CurrentPage"/>
<input value="false" type="hidden" name="TDS_DeviceAuthentication"/>
<input value="0" type="hidden" name="mobileCount"/>
<table width="390" height="400" cellspacing="0" cellpadding="1" bgcolor="#e8e8e8" align="center">
<tr>
<td valign="top">
<table width="100%" style="padding:20px;" height="100%" cellspacing="0" cellpadding="0" border="0" bgcolor="#ffffff">
<tr>
<td valign="top" height="1">
<img width="140" src="../580655198662148898/auth_issuer_logo_vbv.gif" height="47" border="0" align="left"/>
<img width="89" src="../580655198662148898/auth_vbv_lg.gif" height="51" border="0" align="right"/>
</td>
</tr>
<tr>
<td height="20"/>
</tr>
<tr>
<td height="1" colspan="3" align="right">
<font size="-2">
<span style="display:none" name="links">
<a onclick="return openDialog(2,1)" id="langLink_sec" href="#">???</a>
<a style="display:none" id="lang_link_sec">???</a>
 English
</span>
<noscript>
???
 English
</noscript>
</font>
</td>
</tr>
<tr>
<td valign="top" height="1">
<font class="auth_Heading_en">Enter Your Authentication Data</font>
</td>
</tr>
<tr>
<td height="1"/>
</tr>
<tr>
<td valign="top" height="1">
<font class="auth_TxtMain_en">Please enter your</font>
<font class="auth_TxtMain_en">Verified by VISA Password</font>
<font class="auth_TxtMain_en">in the field(s) below to verify your identity for this purchase. This information is not disclosed to the merchant.</font>
</td>
</tr>
<tr>
(part of it very long):
I need to get out from this the value of SSID (1710d5e8428fd9d53db2fe7cfb1c79a5af0ecce).
Tried:
def xml = context.response
def holder = new com.eviware.soapui.support.XmlHolder(xml)
//use the xpath to retrieve the desctiption.
def ParRes = holder.getNodeValues("//*:input/#value")
//logging the descriptions
def str = new StringBuilder();
ParRes.each{
if("$it" != "InitAuth" ){
str = "$it"
}
}
return str
It is easy to handle dynamic response and parse it if Script Assertion is used for the same request step where you get the response. Thus an additional groovy script step can be avoided.
All the changed required is to change 1st statement from
def xml = """
static xml content
"""
to
def xml = context.response
And rest of the solution pointed in your question remains same.
As you have not provided complete response so I took only the form tag:
<form onsubmit="submitAction();return false;" name="submitForm" method="post" action="auth_vbv_browser_authentication.xsl">
<input value="auth_vbv_browser_authentication.xsl" type="hidden" name="AA_CurrentPage"/>
<input value="false" type="hidden" name="TDS_DeviceAuthentication"/>
<input value="0" type="hidden" name="mobileCount"/>
<table width="390" height="400" cellspacing="0" cellpadding="1" bgcolor="#e8e8e8" align="center">
<tr>
<td valign="top">
<table width="100%" style="padding:20px;" height="100%" cellspacing="0" cellpadding="0" border="0" bgcolor="#ffffff">
<tr>
<td valign="top" height="1">
<img width="140" src="../580655198662148898/auth_issuer_logo_vbv.gif" height="47" border="0" align="left"/>
<img width="89" src="../580655198662148898/auth_vbv_lg.gif" height="51" border="0" align="right"/>
</td>
</tr>
<tr>
<td height="20"/>
</tr>
<tr>
<td height="1" colspan="3" align="right">
<font size="-2">
<span style="display:none" name="links">
<a onclick="return openDialog(2,1)" id="langLink_sec" href="#">???</a>
<a style="display:none" id="lang_link_sec">???</a>
English
</span>
<noscript>
???
English
</noscript>
</font>
</td>
</tr>
<tr>
<td valign="top" height="1">
<font class="auth_Heading_en">Enter Your Authentication Data</font>
</td>
</tr>
<tr>
<td height="1"/>
</tr>
<tr>
<td valign="top" height="1">
<font class="auth_TxtMain_en">Please enter your</font>
<font class="auth_TxtMain_en">Verified by VISA Password</font>
<font class="auth_TxtMain_en">in the field(s) below to verify your identity for this purchase. This information is not disclosed to the merchant.</font>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
As per my understanding you want the Value of SSID i.e1710d5e8428fd9d53db2fe7cfb1c79a5af0ecce
and you want to transfer this in next step,so why dont you use Property transfer step and provide Xpath as below:
substring-before(substring-after(/form[#onsubmit="submitAction();return false;"]/table[#width="390"]/tr/td[#valign="top"]/table[#width="100%"]/tr[3]/td[#height="1"]/font[#size="-2"]/noscript/a[#href="auth_vbv_browser_authentication.xsl?AA_CurrentPage=auth_vbv_browser_authentication.xsl&AA_Ignore_Pattern=true&AA_LANCODE=1&SSID=1710d5e8428fd9d53db2fe7cfb1c79a5af0ecce&popup=false"]/#href,"SSID="),"&")
result of this Xpath:1710d5e8428fd9d53db2fe7cfb1c79a5af0ecce
I have tested it on my SOAPUI and working fine.Hope this helps
Note: I have copied Xpath from Form tag,Please change the Xpath as per your requirement,you can use online tools to calulate Xpath or any XML editor.
For more info on Xpath :Check this out

Using watir to click table element without id

I have a dynnamic table that I would like to use watir to select a edit button. It doesn't have a traditional watir id that I can select (example: browser.img(:title, "iconname")) and there may be multiple edit icons to choose from. In the past I would get the correct element by querying the database. However this does not have a database entry to help me select the correct edit link this time.
In the code below what I am trying to select is from the section where it shows "autogenerated3" I am trying to select either the "onclick" element or the "img src"
Both are selectable items that will click the edit icon.
<div id="certificate_table" style="margin-bottom: 1em">
<table cellspacing="0">
<tbody>
<tr>
<th>Alias</th>
<th>Common Name</th>
<th class="centered">Status</th>
<th class="centered">In Use</th>
<th class="centered">Issued</th>
<th class="centered">Expires</th>
<th class="centered">Days</th>
<th>Actions</th>
</tr>
<tr class="normal">
<td>autogenerated2</td>
<td>default.domain.com</td>
<td class="centered"> Revoked </td>
<td class="centered">
<td class="centered"> 10/18/2013 19:46:34 GMT </td>
<td class="centered"> 10/17/2016 19:46:34 GMT </td>
<td class="centered">N/A</td>
<td>
<a onclick="new Ajax.Request('/media/certificates/edit_certificate/3', {asynchronous:true, evalScripts:true}); return false;" href="#">
<img title="Edit" src="/media/images/icons/edit.gif?1276876449" alt="Edit">
</a>
</td>
</tr>
<tr class="alt">
<td>autogenerated3</td>
<td>autogenerated3.domain.com</td>
<td class="centered"> CSR Issued </td>
<td class="centered">
<td class="centered"> 10/18/2013 20:54:55 GMT </td>
<td class="centered"> 10/17/2016 20:54:55 GMT </td>
<td class="centered">1092 </td>
<td>
<a onclick="new Ajax.Request('/media/certificates/edit_certificate/4', {asynchronous:true, evalScripts:true}); return false;" href="#">
<img title="Edit" src="/media/images/icons/edit.gif?1276876449" alt="Edit">
</a>
<a onclick="new Ajax.Request('/media/certificates/generate_csr/4', {asynchronous:true, evalScripts:true}); return false;" href="#">
<a onclick="new Ajax.Request('/media/certificates/import_certificate_reply/4', {asynchronous:true, evalScripts:true}); return false;" href="#">
<a onclick="if (confirm('Are you sure you want to revoke this certificate?')) { new Ajax.Request('/media/certificates/revoke_certificate/4', {asynchronous:true, evalScripts:true}); }; return false;" href="#">
</td>
</tr>
<tr class="normal">
<td>Original Certificate</td>
<td>localhost.localdomain</td>
<td class="centered"> Self Signed </td>
<td class="centered">
<td class="centered"> 10/03/2013 22:37:02 GMT </td>
<td class="centered"> 10/03/2014 22:37:02 GMT </td>
<td class="centered">347 </td>
<td>
<a onclick="new Ajax.Request('/media/certificates/edit_certificate/1', {asynchronous:true, evalScripts:true}); return false;" href="#">
<img title="Edit" src="/media/images/icons/edit.gif?1276876449" alt="Edit">
</a>
</td>
</tr>
<tr class="alt">
<td>vhost4</td>
<td>vhost4.domain.com</td>
<td class="centered"> Revoked </td>
<td class="centered">
<td class="centered"> 10/18/2013 15:58:01 GMT </td>
<td class="centered"> 10/17/2016 15:58:01 GMT </td>
<td class="centered">N/A</td>
<td>
<a onclick="new Ajax.Request('/media/certificates/edit_certificate/2', {asynchronous:true, evalScripts:true}); return false;" href="#">
<img title="Edit" src="/media/images/icons/edit.gif?1276876449" alt="Edit">
</a>
</td>
</tr>
</tbody>
</table>
I don't have trouble selecting a icon. Just trouble selecting the correct icon. Both the onclick and image values are selectable items. The icon may not be the last item in the list. I saw a post to try .last.click which does select the last icon in the list. Unfortunately the table posts the data in alphabetical order based on the Alias name. So it may not be the last item in the list and cannot use this method. Suggestions?
b.div(:id, "certificate_table").imgs(:src => "/media/images/icons/edit.gif?1276876449").last.when_present.click
It sounds like you need to find an element based on its siblings, so you might find this blog post useful. The post gives two options you might consider.
If the text you are looking for is unique - ie the row that has the text is definitely going to be the right row, you can find the td, go to the parent row and then get the link.
b.td(:text => 'autogenerated3').parent.link.click
If you need to ensure that the text is in the first column, then you can do:
b.trs.find{ |tr|
tr.td.exists? and tr.td(:index => 0).text == 'autogenerated3'
}.link.click
The tr.td.exists? is added since some of your rows do not have any tds, which would cause an exception when checking the second criteria.

cellSpace not working in DreamWeaver CS6

I've pasted table code to new div in gridContainer div (using the Fluid Grid Layout option)
Everything seems fine but the cell spacing defined, when I try to change the spacing nothing happens, it keeps it on 0.
Following is the table markup:
<table align="center" cellpadding="0" cellspacing="15">
<col span="7" width="160px" />
<row span="7" width="160px" />
<!---Row 1--->
<tr align="center" height="160px">
<td colspan="2" >
<img src="images/buttons/Optimus.png" />
</td>
<td colspan="2" >
<img src="images/buttons/MapleSim.png">
</td>
<td colspan="2" >
</td>
<td colspan="1" bgcolor="#40b040">
<img src="images/buttons/about_us.png">
</td>
</tr>
<!---Row 2--->
<tr align="center" height="160px">
<td colspan="2" bgcolor="#40b040">
<img src="images/buttons/QFD.white.png">
</td>
<td colspan="1" bgcolor="#cc00cc">
<img src="images/buttons/learning_maple.png">
</td>
<td colspan="3" rowspan="2"
align="left" valign="top" bgcolor="#aaaaff">
<img src="images/buttons/news.png">
News will be shown here
</td>
<td colspan="1" bgcolor="#ff0000">
<img src="images/buttons/services.png">
</td>
</tr>
<!---Row 3--->
<tr align="center" height="160px">
<td colspan="1" bgcolor="#6766cc">
<img src="images/buttons/events.png">
</td>
<td colspan="1" bgcolor="#cccc00">
<img src="images/buttons/forum.png">
</td>
<td colspan="1" bgcolor="#4040ff">
<img src="images/buttons/links.png">
</td>
<td colspan="1" bgcolor="#ffbf00">
<img src="images/buttons/shopping_cart.png">
</td>
</tr>
<!---Row 4--->
<tr align="center" height="160px">
<td colspan="2" bgcolor="#ff0000">
<img src="images/buttons/commercial_users.png">
</td>
<td colspan="1" bgcolor="#ffbf00">
<img src="images/buttons/student_special.png">
</td>
<td colspan="1" bgcolor="#40b000">
<img src="images/buttons/student_special.png">
</td>
<td colspan="1" bgcolor="#ff00cc">
<img src="images/buttons/instruction.png">
</td>
<td colspan="1" bgcolor="#cc00cc">
<img src="images/buttons/learning_maple.png">
</td>
<td colspan="1" bgcolor="#4040ff">
<img src="images/buttons/download.png">
</td>
</tr>
</table>
You can see in this line <table align="center" cellpadding="0" cellspacing="15"> the spacing is 15, but when checking on any browser it shows as it set to 0
Any ideas how to solve it?
Thanks in advance,
Shahar
Ok, I guess I was too hasty.
It appears that the table used two definitions from boilerplate.css
table {
/* [disabled]border-collapse: collapse; */
/* [disabled]border-spacing: 0; */
}
As you can see, simply disabling them resolved the issue.
If there is any other option to override without disabling (maybe usage of !important) I'll be glad to know about it.

Resources