Get the first child node using the Internet Explorer COM object - com

I got a website with the following code:
<div id="past">
<div data-rollid="99999" class="ball kugel-2">2</div>
<div data-rollid="99998" class="ball kugel-2">2</div>
<div data-rollid="99997" class="ball kugel-2">2</div>
I want to get this number "2". I know that I can pickup the "past" by
past := wb.document.getElementById("past")
but how to get the value from the first child node?

You don't give a lot to work with, but you might try, for the first "undertag":
wb.Document.getElementByID("past").childnodes.item[0].innerText
For the second "undertag":
wb.Document.getElementByID("past").childnodes.item[1].innerText
etc.
Else, look at something like this:
wb.document.body.querySelector("data-rollid='99998']").innerText;
or
wb.document.getElementByID("past").querySelector("data-rollid='99998']").innerText;
or even
wb.document.getElementByID("past").childnodes.querySelector("data-rollid='99998']").innerText;
Which might work (you might have to play around with the syntax) . . .
Hth,

This can get you all the elements of a certain class:
elements:=ie.document.getElementsByClassName("ball kugel-2")
Or you can do this:
past:= wb.document.getElementById("past")
children:=past.children
while(a_index <= children.length, i:=a_index-1)
msgbox, % children[i].innertext

Related

Load div on page load and then every n seconds with htmx?

With HTMX I know I can poll e.g. "/news" every 2 seconds like this:
<div hx-get="/news" hx-trigger="every 2s">div>
But it takes 2s before the is triggered the first time after page load. What I want to do is to trigger the call to "/news" as soon as the page is loaded and then poll every 2s.
I've tried things such as:
<div hx-get="/news" hx-trigger="on load or every 2s">div>
and
<div hx-get="/news" hx-trigger="on htmx:afterOnLoad or every 2s">div>
But none of this works. How can I do this with HTMX?
(I know this is generally a bad practice with HTMX since you could just include the data from the server in the response, but I'd like to know out of curiosity :))
You can add multiple triggers separated by comma. So this should probably work:
<div hx-get="/news" hx-trigger="load, every 2s">div>

Selenium finding elements returns incorrect elements

I'm using Selenium to try and get some elements on a web page but I'm having trouble getting the ones I want. I'm getting some, but they're not the ones I want.
So what I have on my page are five divs that look like this:
<div class="membershipDetails">
Inside each one is something like this:
<div class="membershipDetail">
<h3>
VIP Membership
</h3>
</div>
They DO all have this same link, but they don't have the same text ('VIP Membership' would be replaced by something else)
So the first thing was to get all the divs above in a list. This is the line I use:
listElementsMembership = driver.find_elements_by_css_selector(div[class^='membershipDetail'])
This gives me five elements, just as I would expect. I checked the 'class' attribute name and they are what I would expect. At this point I should say that they aren't all EXACTLY the same name 'membershipDetail'. Some have variations. But I can see that I have all five.
The next thing is to go through these elements and try and get that element which contains the href ('VIP Membership').
So I did that like this:
for elem in listElementsMembership:
elemDetailsLink = elem.find_element_by_xpath('//a[contains(#href,"EditMembership")]')
Now this does return something, but it always got me the element from the FIRST of the five elements. It's as if the 'elem.find_element_by_xpath' line is going up a level first before finding these hrefs. I kind of confirmed this by switching this to a 'find_elements_by_xpath' (plural) and getting, you guessed it, five elements.
So is this line:
elemDetailsLink = elem.find_element_by_xpath('//a[contains(#href,"EditMembership")]')
going up a level before getting its results? If it is, now can I make it not do that and just restrict itself to the children?
If you are trying to find element with in an element use a . in the xpath like below:
listElementsMembership = driver.find_elements_by_css_selector(div[class^='membershipDetail'])
for elem in listElementsMembership:
elemDetailsLink = elem.find_element_by_xpath('.//a') # Finds the "a" tag with respect to "elem"
Suppose if you are looking for VIP Membership:
listElementsMembership = driver.find_elements_by_css_selector(div[class^='membershipDetail'])
for elem in listElementsMembership:
value = elem.find_element_by_xpath('.//a').get_attribute("innerText")
if "VIP Membership" in value:
print(elem.find_element_by_xpath('.//a').get_attribute("innerText"))
And if you dont want iterate over all the five elements try to use xpath like below: (As per the HTML you have shared)
//div[#class='membershipDetail']//a[text()='VIP Membership']
Or
//div[#class='membershipDetail']//a[contains(text(),'VIP Membership')]
You've few mistake in that css selector.
Quotes are missing.
^ is for starts-with, not sure if you really need that. In case it's partial matching please use * instead of ^
Also, I do not see any logic for the below statement in your code attempt.
The next thing is to go through these elements and try and get that
element which contains the href ('VIP Membership').
Code :
listElementsMembership = driver.find_elements_by_css_selector("div[class*='membershipDetail']")
for ele in listElementsMembership:
e = ele.find_element(By.XPATH, ".//descendant::a")
if "VIP Membership" in e.get_attribute('href'):
print(e.text, e.get_attribute('href'))
You can give an index using a square bracket like this.
elemDetailsLink = elem.find_element_by_xpath('(//a[contains(#href,"EditMembership")])[1]')
If you are trying to get an element using XPath, the index should start with 1, not 0.

Vue.js get element by id/ref

I have a custom component called 'menu-entry':
<menu-entry v-for="field in fields" :id:"field.id" :ref="field.id" v-bind:key="field.id" v-bind:class="[classArray]" v-bind:field="field" v-on:clicked="menuEntryClicked">
</menu-entry>
I need to get one of them (for example field.id = 2) and remove an item from the classArray.
this.$refs[2] is working for HTML elements, but not for custom elements.
this.$el.querySelector isnt working either.
is there another way to remove an item from the classArray of a specific element?
Your question it is not clear but you are trying to set id and ref to field.id so following this logic it is not necessary to do though.
You can just send the id to the method you are executing like below:
<menu-entry
v-for="field in fields"
v-bind:key="field.id"
v-bind:class="[classArray]"
v-bind:field="field"
v-on:clicked="menuEntryClicked(field.id)" // <= send the id here
>
</menu-entry>
I am not sure if i helped but regarding your question, now you can figoure out which id of element is clicked and remove it from classArray or whatever you want
2 is not a valid id selector when you use document.querySelector('#2'); maybe you can use document.getElementById('2') instead - it can work.

nightwatchjs selector is not selecting an attribute with space

I have a few pages on which I am running nightwatchjs to execute an end to end test.
<div role="tab" aria-selected="true" title="My TV"><span>MyReal TV</span></div>
I have a few tabs that I try to verify using code similar to below:
.verify.elementPresent('div[role="tab"][title="Portfolio"]', 1000)
The above works fine for the Portfolio tab. However, I have two tabs that fail and is returning not found. My Tv and Daily Report . Below fails for My Tv:
.verify.elementPresent('div[role="tab"][title="My Tv"]', 1000)
The Daily Report fails as well. I am wondering if it has something to do with the space in my title? Is there anything else I am doing wrong?
It turns out the url was wrong in my case. It was frustrating, spent hours to learn this.
Something like below was returned for the url
http://stackoverflow.com//questions
Instead of
http://stackoverflow.com/questions

protractor getText returns empty string for non-empty element

I have issues getting the text from an element in protractor. For other elements of the page it works as expected, just not for this one :/
<p class="error theme-info-i ng-binding ng-scope" ng-if="firstFormError && form.$invalid" ng-click="goToErrorField(firstFormError)">
<span class="emphasize ng-binding">User ID</span> (The user ID is required.)
</p>
I can locate both elements without problems using by.className, and getInnerHtml/getOuterHtml works as expected. However getText returns an empty string for both.
Found the reason ... its a two-step registration where the first step has the same notification area and just gets hidden. For reasons beyond my comprehension the devs update both notification areas (not just the one on the current page), so inner/outerHtml just seemingly returned the "correct content" and because the first area was hidden, getText returned empty as by spec.
I think I'm gonna file some internal bug report now wtf we are doing with those notifications ;)
You can try
var firstName = element(by.model('firstName'))
expect(firstName.getAttribute('value'))
This gives you the value of the input box.
Had the same problem.
expect(element(By.css('span.emphasize.ng-binding')).getAttribute('textContent'))...
Seems to work just fine for me (this of course if you have only one span with those classes or is the first one. else you need to be more specific. But anyway if you still need to solve the problem try with .getAttribute('textContent') )