Item Selection from combo-box using vba in Internet Explorer - excel

The below values represent a combobox / combo-list on a website. I am trying to select item #3 from the drop down using VBA. I have tried several things, but I have had no luck selecting said item. I have tried looking for solutions on Google and the Stack but haven't found anything that seems to work.
<DIV id=ext-gen256 class="x-layer x-combo-list x-combo-list-small" style="FONT-SIZE: 10px; HEIGHT: 92px; WIDTH: 113px; POSITION: absolute; LEFT: 744px; Z-INDEX: 12007; TOP: 235px; VISIBILITY: visible">
<DIV id=ext-gen257 class=x-combo-list-inner style="HEIGHT: 90px; WIDTH: 111px">
<DIV class="x-combo-list-item" _nodup="30829" viewIndex="0">Select</DIV>
<DIV class="x-combo-list-item" _nodup="30829" viewIndex="1">Item 1</DIV>
<DIV class="x-combo-list-item" _nodup="30829" viewIndex="2">Item 2</DIV>
<DIV class=""x-combo-list-item" _nodup="30829" viewIndex="3">Item 3</DIV>
<DIV class="x-combo-list-item" _nodup="30829" viewIndex="4">Item 4</DIV></DIV></DIV>
I have used several variatons of the below code to try and select the item in question (i.e item #3), but keep getting a runtime error
Dim inputE As MSHTML.HTMLHtmlElement
Set inputE = IE.document.getElementsByClassName("x-combo-list-item")
If inputE.innerText = "Item 3" Then
inputE.Select
End If
This doesn't seem to work. Any help is greatly appreciated. Thanks!

Related

Fix width of Text in Bootstrap

How can I fix the width of text so that it remains splitted in two columns
<div class="container">
<div class="row">
<div class="col-lg-6"><ol id="AllMessages"></ol></div>
<div class="col-lg-6">
<h1>Last Broadcasted Message:</h1>
<h3
id="output"
class="float-left"
style="
margin-top: 35px;
border-top: 1px solid #dedbdb;
padding: 15px;
width: 120px;
"
></h3>
</div>
</div>
</div>
A few observations
It looks like the text in the image is put in without any space, this will usually break the layout - see the portion width:width:width etc.
Your Markup is also incorrect as it contains ol elements without li
Using inline styles on top of bootstrap is probably not a good idea as it breaks margins etc.
Most likely it's the text without non breaking text characters that is breaking your layout.

How to add a tick to a checkbox through excel vba ie automation?

The checkbox I am trying to add a tick to is part of an online table and doesn't seem to be coded as a checkbox.
I have tried the following to add a tick and none work:
IE.Document.getElementByID("gridcolumn-1658-titleEl").Click
IE.Document.getElementByID("gridcolumn-1658-textEl").Click
IE.Document.getElementsByClassName("x-column-header-inner x-column-header-over")(0).Click
IE.Document.getElementsByClassName("x-column-header-inner")(0).Click
When I inspect the element, I get to the following, but none of this looks anything like a checkbox (the third one is the actual reference):
<div class="x-column-header x-column-header-checkbox x-column-header-align-left x-box-item x-column-header-default x-unselectable x-column-header-first" style="border-width: 1px; width: 24px; right: auto; left: 0px; top: 0px; margin: 0px; height: 24px;" id="gridcolumn-1658"><div id="gridcolumn-1658-titleEl" class="x-column-header-inner" style="padding-top: 6px; padding-bottom: 6px;"><span id="gridcolumn-1658-textEl" class="x-column-header-text"> </span></div></div>
<div id="gridcolumn-1658-titleEl" class="x-column-header-inner" style="padding-top: 6px; padding-bottom: 6px;"><span id="gridcolumn-1658-textEl" class="x-column-header-text"> </span></div>
<span id="gridcolumn-1658-textEl" class="x-column-header-text"> </span>
The website is OptimoRoute, which can be accessed fairly quickly using a new log in, for those interested!
The button I am trying to click is the top one in the table.
Please refer to the following sample code:
Sub main()
'we define the essential variables
Dim IE As Object, Data As Object
Dim ticket As String
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.navigate ("https://dillion132.github.io/vbacheckbox.html")
While IE.ReadyState <> 4
DoEvents
Wend
Set Data = IE.Document.getElementsByClassName("check")
Debug.Print Data.Length
If Len(Data) > 0 Then
For Each ee In Data
'Debug.Print ee.Value
'Based on the checkbox value to check/uncheck the checkbox.
If ee.Value = "Cat" Then
ee.Checked = True
End If
'check whether the checkbox is checked, then, get the checked value.
If ee.Checked Then
Debug.Print ee.Value & " is checked"
End If
Next ee
End If
End With
Set IE = Nothing
End Sub
Code in the website:
<input class="check" type="checkbox" value="Cat"> Cat </input>
<br />
<input class="check" type="checkbox" value="Dog" >Dog</input>
<br />
<input class="check" type="checkbox" value="Pig" checked ="checked" >Pig</input>
The result as below:

How to select and click dropdown menu item with selenium

I'm looking to sort a webpage from low price to high price by using the built-in product sort
I am able to successfully select the correct dropdown menu using xpath as follows:
WebDriverWait(driver, 5).until(
EC.element_to_be_clickable((By.XPATH,
'//*[#id="react-views-container"]/div/div/div/div[1]/div/div/div/div[2]/div[1]/div/div[2]/div/div[1]/button')))
This was intended only to be a test of sorts, as I am still relatively new to selenium. However, given this worked I cannot understand why the following does not:
WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH,
'//*[#id="react-views-container"]/div/div/div/div[1]/div/div/div/div[1]/div/div[1]/div/div[2]/div/div/div/div/div[4]')))
This results in an error whereby the timeout is reached. It is not an issue of the timeout being too short. I have tried the div search for the given text, but that also did not work. Here is one example of the search I tried which was nearly copied from a similar question:
Select(driver.find_element_by_xpath("//div[contains(text(), 'Unit Price: Low First')]"))
Here is the HTML for the desired menu item:
<div role="menuitem" tabindex="0" data-radium="true" style="background-color: rgb(247, 247, 247); padding: 8px 16px; font-size: 16px; font-weight: normal; color: white; white-space: nowrap; line-height: 20px; min-width: 260px; height: 36px; cursor: pointer;">
<div data-radium="true" style="float: left; display: block; line-height: 24px;">Unit Price: Low First</div>
</div>
Ok so that was a bit of a painful lesson in html and Selenium. Anyway, I figured it out by creating a list of all the menu items and then iterating through that list and clicking on the one I wanted. At the moment, I have this:
menu_items=driver.find_elements_by_xpath('//div[#role="menuitem"]')
for i in menu_items:
if "Unit Price" in i.text:
i.click()
break
For some reason I cannot just do menu_items[4].click(), but I believe it is due to the elements list being a list of tuples or something, though I will have to check the documentation to verify this. I will update the answer afterwards.

Scraping IE with VBA, how to scroll to bottom of page?

I am pretty new to VBA. I'm trying to scroll to the bottom of a web page. Below is contents of web page.
<DIV id="Table">
<div style="width: 18px; overflow: auto; height: 912px;" onscroll="Grids[0].Scrolled();" onmousemove="Grids[0].ARow=null;Grids[0].ASec=-1;"><div style="width: 1px; overflow: hidden; height: 1954px;"> </div></div>'
This is VBA Code I have so far.
Dim selector As String
selector = "#Table div[style*='onmousemove']"
Dim rightWindowDiv As HTMLDivElement
Set rightWindowDiv = htmldoc.querySelector(selector)
rightWindowDiv.ScrollTop = rightWindowDiv.ScrollHeight
Somehow it does not work. Can someone help?

Primefaces Spinner required to Input formatted number

In a Java project we are using PrimeFaces 2.2.1 as a JSF extension. We are implementing in a register form the data of schedule as "Load hours" separated in two fields, hours and minutes. We are using the Spinner (p:spinner component) as input element. However, we need to show the current data (only integers) in the format that show at least two numbers when value is less than 10.
Current input format
Needed input format
The body of the JSF tags look as this:
<div class="form_block">
<div class="form_item">
<h:outputText styleClass="form_item_label" value="Load Hours:"/>
<div class="form_item_field">
<p:spinner id="hora" styleClass="spinnerField" style="height: 12px !important; box-shadow: none !important; border-radius: 4px 0px 0px 4px;"
value="#{hour}" min="00" max="23"><f:convertNumber pattern="00" minIntegerDigits="2" type="number"/></p:spinner>:
<p:spinner id="minutos" styleClass="spinnerField" style="height: 12px !important; box-shadow: none !important; border-radius: 4px 0px 0px 4px;"
value="#{minutes}" min="00" max="59" maxlength="2"><f:convertNumber pattern="00" minIntegerDigits="2" type="number"/></p:spinner>
</div>
<div class="clear"></div>
</div>
</div>
We have also try formatting with f:convertNumber component within Spinner but seems to not work as we expect. Has anybody else had similar problems like this before? Any suggestions you might share? Thanks in advance
Note. We did not implement timepicker due to the fact we precise to handle each field (hours and minutes) separated.
Actually, I had to change the components. Instead of using p:spinner it is know implemented p:inputMask.

Resources