How to hover and click on hidden elements with Selenium Basic using VBA? - excel

I followed a couple of solutions to this problem on this platform, especially Trouble selecting a hidden menu item using SeleniumBasic for vba
I was able to hover through the menu of the website I'm trying to automate, but I'm unable to click on the table row (Claims Submission) which is the second option when the table/form is visible.
My initial goal was to hover the visible menu of the page to show a drop down and I achieved that with a loop.
Now when the (claims) Menu is visible I need to click on the second option (Claims Submission) of that table. As directed from Trouble selecting a hidden menu item using SeleniumBasic for vba I attempted to use an xpath to reference the element.
It returned
Run-time error '7':
NoSuchElementError
Element not found for XPath=//a[.//span[contains(.,'Claims Submission')]]
Private WB As Selenium.WebDriver
Sub Test()
Set WB = New Selenium.ChromeDriver
WB.Start
WB.Get "https://health.axamansard.com/axamansardProviderlogin/Index.aspx"
Dim Menu As WebElement
Dim Menus As WebElements
Dim MenuSubmission As WebElement
WB.FindElementByName("txtUname").SendKeys "Almadina"
WB.FindElementByName("txtPass").SendKeys "Nhisdesk#1234"
WB.FindElementByName("btnSubmit").Click
Set Menus = WB.FindElementsByClass("a")
For Each Menu In Menus
If Menu.Text = "Claims" Then
WB.Mouse.MoveTo Menu
Set MenuSubmission = WB.FindElementByXPath("//a[.//span[contains(.,'Claims Submission')]]")
MenuSubmission.Click
End If
Next
End sub
WebScript
<table class="menu" id="Claims" width="150px" bgcolor="white" style="visibility: hidden;">
<tbody><tr height="19px">
<td class="menu"><a class="a"
href="../Forms/ClaimsBatch.aspx">Claims Batch</a></td>
</tr>
<tr height="19px">
<td class="menu"><a class="a"
href="../Forms/ClaimSubmission.aspx">Claims Submission</a></td>
</tr>
<tr height="19px">
<td class="menu"><a class="a"
href="../Forms/ClaimSubmissionList.aspx">Claims Submission List</a></td>
</tr>
<tr height="19px">
<td class="menu"><a class="a"
href="../Forms/ClaimsUpload.aspx">Claims Upload</a></td>
</tr>
<tr height="19px">
<td class="menu"><a class="a"
href="../Forms/Calimreviewlist.aspx">Claims Status</a></td>
</tr>
<tr height="19px">
<td class="menu"><a class="a"
href="../Forms/ProviderClaimsBatchDetails.aspx">Provider Claims Batch Details/Claim Credit Note Details</a></td>
</tr>
</tbody></table>

The xpath to the link Claims Submission seems a bit off. You can use either of the following Locator Strategies:
FindElementByXPath:
WB.FindElementByXPath("//table[#id='Claims']//td/a[.='Claims Submission']").Click
FindElementByXPath relative to Claims:
WB.FindElementByXPath("//a[.='Claims']//following::table[1]//td/a[.='Claims Submission']").Click

Related

How to get all td[3] tags from the tr tags with selenium Xpath in python

I have a webpage HTML like this:
<table class="table_type1" id="sailing">
<tbody>
<tr>
<td class="multi_row"></td>
<td class="multi_row"></td>
<td class="multi_row">1</td>
<td class="multi_row"></td>
</tr>
<tr>
<td class="multi_row"></td>
<td class="multi_row"></td>
<td class="multi_row">1</td>
<td class="multi_row"></td>
</tr>
</tbody>
</table>
and tr tags are dynamic so i don't know how many of them exist, i need all td[3] of any tr tags in a list for some slicing stuff.it is much better iterate with built in tools if find_element(s)_by_xpath("") has iterating tools.
Try
cells = driver.find_elements_by_xpath("//table[#id='sailing']//tr/td[3]")
to get third cell of each row
Edit
For iterating just use a for loop:
print ([i.text for i in cells])
Try following code :
tdElements = driver.find_elements_by_xpath("//table[#id="sailing "]/tbody//td")
Edit : for 3rd element
tdElements = driver.find_elements_by_xpath("//table[#id="sailing "]/tbody/tr/td[3]")
To print the text e.g. 1 from each of the third <td> you can either use the get_attribute() method or text property and you can use either of the following solutions:
Using CssSelector and get_attribute():
print(driver.find_elements_by_css_selector("table.table_type1#sailing tr td:nth-child(3)").get_attribute("innerHTML"))
Using CssSelector and text property:
print(driver.find_elements_by_css_selector("table.table_type1#sailing tr td:nth-child(3)").text)
Using XPath and get_attribute():
print(driver.find_elements_by_xpath('//table[#class='table_type1' and #id="sailing"]//tr//following::td[3]').get_attribute("innerHTML"))
Using XPath and text property:
print(driver.find_elements_by_xpath('//table[#class='table_type1' and #id="sailing"]//tr//following::td[3]').text)
To get the 3 rd td of each row, you can try either with xpath
driver.find_elements_by_xpath('//table[#id="sailing"]/tbody//td[3]')
or you can try with css selector like
driver.find_elements_by_css_selector('table#sailing td:nth-child(3)')
As it is returning list you can iterate with for each,
elements=driver.find_elements_by_xpath('//table[#id="sailing"]/tbody//td[3]')
for element in elements:
print(element.text)

I'm trying to select and item from a dropdown kendolistbox in IE with Excel Vba

I found a solution to choosing a fixed selection from a dropdown list. Now all I have to do is figure out how to choose an item based on the choices.
The following chooses the first item in the dropdown, however, I found out that making the dropdown "open" is not necessary.
Changing the select parameter to 2 chooses the second item in the list etc.
I suppose trying to use getElementById and cycling through the innerText may be the way to go, since I don't know any other way.
ie.Document.parentWindow.execScript "$('#drgdTankCrude').data('kendoGrid').dataItem($('#Tank_ID').data('kendoDropDownList').select(1));"
Here a section of the web page code.
<input name="Tank.ID" id="Tank_ID" style="width: 200px; display: none;" type="text" data-role="dropdownlist"></span>
'Lots of other stuff in here for formatting
<div class="k-widget k-grid" id="drgdTankCrude" style="left: 890.32px; top: 93.7px; display: block; position: absolute;" data-role="grid">
<table class="k-selectable" role="grid" style="-ms-touch-action: double-tap-zoom pinch-zoom;" data-role="selectable">
<colgroup><col><col></colgroup>
<thead class="k-grid-header" role="rowgroup">
<tr role="row">
<th class="k-header" scope="col" data-title="Tank" data-index="0" data-field="ID"><span class="k-link">Tank</span></th>
<th class="k-header" scope="col" data-title="Capacity" data-index="1" data-field="Capacity"><span class="k-link">Capacity</span></th>
</tr>
</thead>
<tbody role="rowgroup">
<tr class="k-state-selected" aria-selected="true">
<td>179800</td>
<td>202.06</td></tr>
<tr class="k-alt" aria-selected="false">
<td>179801</td>
<td>202.82</td>
</tr>
</tbody>
</table>
</div>
'Code before dropdown
<tbody role="rowgroup">
<tr>
<td>179800</td>
<td>202.06</td></tr>
<tr class="k-alt">
<td>179801</td>
<td>202.82</td>
</tr>
</tbody>
'Code before dropdown opens
<div class="k-widget k-grid" id="drgdTankCrude" style="left: 890.32px; top: 93.71px; display: none; position: absolute;" data-role="grid">
'Code change after dropdown opens
<div class="k-widget k-grid **k-custom-visible**" id="drgdTankCrude" style="left: 890.32px; top: 93.71px; display: block; position: absolute;" data-role="grid">
'Code change after making a selection
<tbody role="rowgroup">
<tr class="k-state-selected" aria-selected="true">
<td>179800</td> '<<-----This item selected
<td>202.06</td></tr>
<tr class="k-alt" aria-selected="false"> '<<--If selected then unselected
<td>179801</td> 'otherwise ends at k-alt">
<td>202.82</td>
</tr>
</tbody>
The answer to selecting the first item in a kendoDropDownList ..
ie.Document.parentWindow.execScript "$('#drgdTankCrude').data('kendoGrid').dataItem($('#Tank_ID').data('kendoDropDownList').select(1));"

VBA Excel get text inside HTMLObject

I know this is really easy for some of you out there. But I have been going deep on the internet and I can not find an answer. I need to get the company name that is inside the
tbody tr td a eBay-tradera.com
and
td class="bS aR" 970,80
/td /tr /tbody
<tbody id="matrix1_group0">
<tr class="oR" onmouseover="onMouseOver(this, false)" onmouseout="onMouseOut(this, false)" onclick="onClick(this, false)">
<td class="bS"> </td>
<td>
<a href="aProgramInfoApplyRead.action?programId=175&affiliateId=2014848" title="http://www.tradera.com/" target="_blank">
eBay-Tradera.com
</a>
</td>
<td class="aR">
175</td>
<td class="bS aR">0</td><td class="bS aR">0</td><td class="bS aR">187</td>
<td class="aR">0,00%</td><td class="bS aR">124</td>
<td class="aR">0,00%</td>
<td class="bS aR">26</td>
<td class="aR">20,97%</td>
<td class="bS aR">32</td>
<td class="aR">60,80</td>
<td class="aR">25,81%</td>
<td class="bS aR">5 102,00</td>
<td class="bS aR">0,00</td>
<td class="aR">0,00</td>
<td class="bS aR">
970,80
</td>
</tr>
</tbody>
This is my code, where I only try to get the a tag to start of with but I cant get that to work either
Set TDelements = document.getElementById("matrix1_group0").document.getElementsbytagname("a").innerHTML
r = 0
C = 0
For Each TDelement In TDelements
Blad1.Range("A1").Offset(r, C).Value = TDelement.innerText
r = r + 1
Next
Thanks on beforehand I know that this might be to simple. But I hope that other people might have the same issue and this will be helpful for them as well. The reason for the "r = r + 1" is because there are many more companies on this list. I just wanted to make it as easy as I could. Thanks again!
You will need to specify the element location in the table. Ebay seems to be obfuscating the class-names so we cannot rely on those being consistent. Nor would I usually rely on the elements by their table index being consistent but I don't see any way around this.
I am assuming that this is the HTML document you are searching
<tbody id="matrix1_group0">
<tr class="oR" onmouseover="onMouseOver(this, false)" onmouseout="onMouseOut(this, false)" onclick="onClick(this, false)">
<td class="bS"> </td>
<td>
<a href="aProgramInfoApplyRead.action?programId=175&affiliateId=2014848" title="http://www.tradera.com/" target="_blank">
eBay-Tradera.com <!-- <=== You want this? -->
</a>
</td>
<!-- ... -->
</tr>
<!-- ... -->
</tbody>
We can ignore the rest of the document as the table element has an ID. In short, we assume that
.getElementById("matrix1_group0").getElementsByTagName("TR")
will return a collection of html row objects sorted by their appearance.
Set matrix = document.getElementById("matrix1_group0")
Set firstRow = matrix.getElementsByTagName("TR")(1)
Set firstRowSecondCell = firstRow.getElementsByTagName("TD")(2)
traderaName = firstRowSecondCell.innerText
Of course you could inline this all as
document.getElementById("matrix1_group0").getElementsByTagName("TR")(1).getElementsByTagName("TD")(2).innerText
but that would make debugging harder. Also if the web-page is ever presented to you in a different format then this won't work. Ebay is deliberately making it hard for you to scrape data off of it for security.
With only the HTML you have shown you can use CSS selectors to obtain these:
a[href*='aProgramInfoApplyRead.action?programId']
Which says a tag with attribute href that contains the string 'aProgramInfoApplyRead.action?programId'. This matches two elements but the first is the one you want.
CSS Selector:
VBA:
You can use .querySelector method of .document to retrieve the first match
Debug.Print ie.document.querySelector("a[href*='aProgramInfoApplyRead.action?programId']").innerText

JavaFX hide text of column in tableview

I have a tableview and I want to show an image in the first column. My problem is I can't sort the column then. My idea is to set text in the column too and hide the text so it is only for the correct sorting set. Is there a way to do that? Or what other solutions are possible for my problem?
I think this is the perfect example what you wants to do.Still let me know if you have any issue.
Check here
I would have a look at TableColumn.setCellValueFactory() and TableColumn.setCellFactory(). The further is used to provide the actual cell value (used for sorting!), the latter is used to provide the rendering.
In other words: If you need the sort order, you must not change the content, but only the Cell rendering. The methods mentioned above let you do exactly this.
Hope that helps ...
You could do it with just CSS using text-indent. You would also need to set the image as a css background. You did not provide an code of your table, but below is some example:
HTML:
<table width="100%" border="1" cellspacing="1" cellpadding="1">
<tr>
<td class="hidetext image">Text 1</td>
<td>Some text to show</td>
</tr>
<tr>
<td class="hidetext image">Text 2</td>
<td>Some text to show</td>
</tr>
<tr>
<td class="hidetext image">Text 3</td>
<td>Some text to show</td>
</tr>
<tr>
<td class="hidetext image">Text 4</td>
<td>Some text to show</td>
</tr>
</table>
CSS:
.hidetext {text-indent:-9000px}
.image {background:url(http://www.madisoncopy.com/images/jpeg.jpg) no-repeat;}
See how in the left column the text does not show (but it is actually there just indented off the screen).
See this fiddle: http://jsfiddle.net/D297P/

Formatting HTML Tables for Excel

I have a page in asp that makes a xls table, however when open the table all the rows are stuffed into the default column width which I would like to set.
My table looks something like this:
<table>
<thead>
'A for loop makes a series of th
</thead>
'another loop pulls db values
<tr><td>value1</td><td>value2</td> 'etc </tr>
</table>
I have tried the following to set the space
width="3.29in"
&nsp; spam (barbaric but sometimes effective)
width="400px"
style="width:300px"
none of the above seem to work.
Additionally here is my header asp incase its relevant
Response.Clear()
Response.Buffer = False
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=blah.xls"
Also on a side note for some reason when I have a dollar value printed as such
<td>$<%=dbvalue%></td>
for some reason this yields '$dollar value and I am not sure how to nuke the single quote.
Do you need the thead tag? Something like this should work:
<html>
<body>
<h1>Report Title</h1>
<table >
<tr>
<th style="width : 300px">header1</th>
<th style="width : 100px">header2</th>
<th style="width : 200px">header..</th>
<th style="width : 300px">....</th>
</tr>
<tr class="row1">
<td >value1</td>
<td >value2</td>
<td >value..</td>
<td >....</td>
</tr>
....
Optionally you can put the table row with th tags inside a <thead> tag

Resources