How to click a plain button on a webpage using VBScript? - vbscript

I have a button on an website like this
<button>
Like
</button>
Does anyone know how to find and click this button using VBScript?
Since he have no ID or other things I don't know how to find the button.

So it seems that I am answering my own questions. The more you search, the fastest you learn.
Set Butlike = IE.Document.getElementsByTagName("button")
if btn.textContent= "Like" then
btn.Click()
End if

Related

RN Web, href in TouchableOpacity: onPress >navigation, onRight click > context menu with possibility to open link

I have a site with TouchableOpacity that uses react-navigation to navigate to another screen. Is it possible in some way to add href to this button so I could open the another screen in new tab using context menu "Open link in new tab"?
I know there is possibility to add accessibilityRole='link' href={''} to a component but what about a whole button of view.
This is according to: https://github.com/necolas/react-native-web/issues/162
Using Text component it is possible by:
<Text
accessibilityRole='link'
href={defineRightClick()}
target='_blank'
onPress={(e) => {
e.preventDefault();
navigateFunction();
}}>
Click to navigate, right click to open in new tab
</Text>
Ask if more information is needed for this question and I will edit it.
Every help is appreciated as I have tried to find solution but have not come across or found a way to handle this case.
Found an answer!
Even thought it is not documented in here: https://necolas.github.io/react-native-web/docs/accessibility/#accessibility-patterns
and using href in TouchableOpacity will show ts error No overload matches this call., it is possible to add to a TouchableOpacity props
accessibilityRole='link'
href={'desired link'}
target='_blank'
Then using e.preventDefault() in onPress event of TouchableOpacity will prevent link opening and do other things assigned to the function. At the same time the link is possible to be opened with right click > context menu > "Open link in new tab"
I will post this as answer so if anyone else comes across this they might find the solution

How to auto click button within iframe with no name or ID in VBScript

I'm trying to create a very simple vbscript but can't make it to do what I want.
I have a webpage lets call it "www.testing.com" that has many buttons (over 10 of them) that look and code the same:
<button type="button" class="text-uppercase promotion__btn btn btn-primary btn-sm">Get started now</button>
As you can see there is no name or ID for the button so I didn't find any solution in all my search for how to click the first button among them all.
My code for opening the webpage is very simple:
set IE = createobject("internetexplorer.Application")
IE.statusbar = false
IE.menubar = false
IE.toolbar = flase
IE.visible = true
IE.navigate("www.testing.com")
wscript.sleep(2000)
I tried to use this code with no success:
For Each btn In IE.Document.getElementsByTagName("button")
If btn.type = "button" Then
btn.Click()
Exit For
End If
Next
Appreciate the help.
Thank you for your time
Edit:
As user Lankymart recommanded 'IE.document.getElementsByTagName("button")(0).Click() does click the first button on the page but not the button that I need it to.
The button that get clicked by this command has the code: <button class="strong-action-button icon-plus js-create-new-catalog full-width">Create New Catalog</button>
While I'm trying to click a button with the code: <button type="button" class="text-uppercase promotion__btn btn btn-primary btn-sm">Get started now</button>
As you can see the button that I want to click on has type="button" so I'm trying to find a way to match Lankymart command with a something else that will help me click button that has that type in its code.
I tried the folloing code but nothing getting clicked and I don't get any error message so I assume I'm doing something wrong:
For Each btn In IE.document.getElementsByTagName("button")
If btn.type = "button" Then
btn.Click()
Exit For
End If
Next
EDIT 2:
My code looks like that right now:
set IE = createobject("internetexplorer.Application")
IE.statusbar = false
IE.menubar = false
IE.toolbar = false
IE.visible = true
IE.navigate("www.testing.com")
wscript.sleep(8000)
For Each btn In IE.document.getElementsByTagName("button")
If btn.innerText = "Get started now" Then
btn.Click()
End If
Next
Running that script open the website but nothing get clicked.
I think the issue is that it only find one button tag which is "Create New Catalog". I tested it by switching the FOR loop to this code:
Set results = ie.document.all.tags("button")
For Each button In results
WScript.Echo button.innerText
Next
After running this code the only output is "Create New Catalog" which I don't understand why is that. Searching within the "inspect element" of the code show that there is 51 tags in the page, so why would it only find that one and not the other 50 buttons?
Edit 3:
So I think the issue is the fact that document.getElementsByTagName return code from the HTML of the site I'm using but when I click "inspect" to see the code of the button I would like to click the code is whole different than the HTML code (The one that show if I click "view page source").
Can that be the issue? if so how do I fix it?
If someone has an idea how I can achieve my goal in a different programming language - I'm open to suggestions, it doesn't have to be VBscript. Thank you
The Solution for the main question is that:
This code search for buttons with tag that the text on the button is "Get started now". That way you basically do not need button ID or Name.
For Each btn In IE.document.getElementsByTagName("button")
If btn.innerText = "Get started now" Then
btn.Click()
End If
Next
Then I had a different problem which even with that code it didn't worked. So the user SearchAndResQ pointed out that in my case the button was under iframe and in order to access it I need to navigate to the iframe and then look for the button that I want to click.
Thank you SearchAndResQ, JNevill and Lankymart for taking your time to help me.

Access button in div popup watir web-driver

I am trying to retrieve, modify, and reinsert some text in a pop up dialog using watir web-driver. All was going swimmingly until I tried to find a way to click the "Save Book Info" button pictured here: http://i.stack.imgur.com/pGdln.png
However I am unable to find the button. To access the pop up box I gather all the links with the correct name into an array:
#browser.imgs.each do |img| #The links are imgs
if img.title.include?('Edit/Delete Book')
#books << img
end
end
From there I can access the links with #books[index].click. I am able to access and edit the text_fields with:
url = #browser.text_field(:name=>'url').value
... do stuff with url ..
#browser.text_field(:name=>'url').set url
But when I try and find the "Close" button I only get the buttons that are on the main page. After many headaches I managed to find the title of the window I want to work with using #browser.div(:class=>'dijitDialogTitleBar').title, which returns "Edit Book". Success! No. I still can't figure out how to access the buttons on that popup!
If anyone could help me with this I would be most grateful. This is my first time using Watir so it's probably a simple answer...
If more information is needed I'd be happy to supply it. Thanks in advance.
EDIT
Here is the html for the button:
<span id="dijit_form_Button_2_label"
class="dijitReset dijitInline dijitButtonText"
dojoattachpoint="containerNode">Save Book Info</span>
It looks like you have a span tag that is styled to be looked like a button. You need to access it is a span instead of a button.
Try:
#browser.span(:text => 'Save Book Info').click

Clicking a button with WATIR WebDriver

I have been struggling with this all morning and was hoping to get some assistance.
I have this button on a webpage that pulls up a control panel that lets the user select which widgets to display. I'm trying to get this to fire using watir webdriver and firefox 9.0 but having no luck at all. I'm able to login to the site, get to the page that contains the button but just can't click the 'CHOOSE YOUR FEATURES' button.
<div class="personalizationButton">
<span class="personalizationStatus"></span>
<b class="widgetPanelLink neo-button button-white">
<span>CHOOSE YOUR FEATURES</span>
</b>
</div>`
I've been concentrating on using div class 'personalizationButton' but perhaps I need to point to that 'b class'? Just not sure how to format it. Here are some examples of what I have tried
$browser.div(:class, 'personalizationButton').when_present.click
$browser.button(:text => 'CHOOSE YOUR FEATURES').click
$browser.button(:div => 'personalizationButton').click
etc, etc... just not sure I'm getting the format right. I watch it get to the page, I see the 'CHOOSE YOUR FEATURES' button on the page, but it never clicks it. Usually I get an error like this depending on which version was used:
unable to locate element, using {:text=>"CHOOSE YOUR FEATURES", :tag_name=>"button"}
This is the version I think should work, When I try it I get no errors but see nothing happen in the browser either:
$browser.div(:class => "personalizationButton").click
I'm not seeing anything inherently clickable (with output) in the HTML. With the IRB output, it shows that it is finding the div, but there is no action when clicking it. The <b> element is just the "bold" style, so we shouldn't need to try that.
If you can access the span with text CHOOSE YOUR FEATURES, that should be your button.
$browser.span(:text => "CHOOSE YOUR FEATURES").click
. . i have tried doing the same thing with godaddy.com buy it did work.
on the main page there is a button labeled "Buy Now" using the code below
brow.div(:class => 'gdhp-domain-link gdhp-rounded-corners').span(:text => 'Buy Now').click
I was

selenium is able to find but unable to click on an unicode character

I am having trouble getting selenium RC to click on a button. There is a button on a page that has the character "pi" on it and I am trying to click on it. The html code looks something like this
<div id="abc">
<a class="my keys one" keystring="Pi" keyvalue="π"
π
</a>
</div>
This is what I have done so far -
selenium.click("//div[#id='abc']/a[1]");
This returns an OK but on the page, when I see visually, the button is not clicked (on click, the page has to do something).
I have tried other stuff like getting the Attribute and making it click on it, but doesnt work-
selenium.click(selenium.getAttribute("//div[#id='abc']/a[1]#keystring"));
I have even tried converting the above selenium.getAttribute to a unicode value and then clicking on it. That does not work too.
Also, I added a line to check if at least selenium thinks the character pi is present on the page. I used the unicode of pi-
selenium.isElementPresent("\u03c0");
On eclipse, when I run it, this shows up- isElementPresent[?, ] on session...
and returns a false.
I am stumped. Can anyone please point to me what is it that I am doing wrong?
i thin this may help you.
selenium.click("//a[#class='my keys one']");
or
selenium.click("xpath=//a[#class='my keys one'"]");
if it is not workin use css path.
I a similar issue. My button has a "black down-pointing triangle" on it and none of the other attributes are unique (the "class", "id", and "role" are reused over and over on the same page). The only unique thing I have is a "value" that is a symbol.
value="▼ "
I, too, would like to know if there is a way to click on this button.

Resources