VBA Macro - How to click a link in java web page - vba

I want to get data from a web page.
web adress:
https://intvrg.gib.gov.tr/intvrg_side/main.jsp?token=d1078f5e3dc646b78d5d4e5842f21e97feb48d366bc7617458b6679dec12675154a01fccc42292bb04d926bc259dbc75e39dd8e202535fd70a7098396c74a6f7
After this page I click "Diger Sorgulamalar" at the right box, then try to click "Vergi Kimlik Numarası Dogrulama"
With vba code after navigating to the web page I can click first link with the code:
IE.document.getElementById("gen__1155").Click
However, I cannot navigate to the "Vergi Kimlik Numarası Dogrulama". I tried:
IE.document.getElementById("H7d190dfed4bed-faf6170603664e").Click
But this does not work. The web source code is like below.
How can I go to that page?

The issue is that H7d190dfed4bed-faf6170603664e does not appear in the HTML code you posted, so it cannot find it. So probably the ID changes everytime the page is accessed so you cannot hardcode the ID.
You need to find something else to determine the correct link. Is the link name Vergi Kimlik Numarası Dogrulama always the same?
Then you could loop through all links and check to find the name of the tag:
For Each lnk In IE.document.GetElementByTagName("a")
If lnk.innerHTML = "Vergi Kimlik Numarası Dogrulama" Then
lnk.Click
Exit For 'if there is only one link with that name you can exit here.
End If
Next lnk

Related

Extract complete URL from a link

I am scrapping amanzon.co.in using scrapy-playwright. I am able to extract description, rating and price of desired item. However for going to next page I want to extract href for Next Page button at the bottom of the page.
Thru scrapy-playwright python code I am able to extract href of next button as : href="/s?k=Soap+for+men&page=2"
When I extract URL using the browser, it appears like : https://www.amazon.in/s?k=soap+for+men&page=2&crid=1A43B14UY65X0&qid=1671472636&sprefix=soap+for+men%2Caps%2C262&ref=sr_pg_1
How do I get generate complete URL from the link including crid extracted thru code ?

VBA macro how to click on button on website on chrome, using Selenium

I am trying to program to click on one button on website on chrome. The name of the button is "Add to Cart".
Please see HTML of the website:
enter image description here
And this is the VBA code:
CD.FindElementByCss("div.addToCartButtons clearAfter > button blue right s-addToCart > span.Add to Cart").Click
How can I do this?
Tags are important, you can anticipate some of the events attached to certain element in DOM just by reading its tag.
In your case you can click on the button tag directly instead of clicking the tag span, since this last one rarely has a .click event attached to it.
If you can provide an url to test this website I might help you better. This are the possible approaches:
1) Advanced:
a. Spaces in class are change for dots
b. Requires to understand tag's meaning and relative position of elements in DOM
'Example
'Clicking first button in div using only tag ("button" is a tag)
CD.FindElementByCss("div.addToCartButtons.clearAfter > button").Click
2) Intermedium:
a. Use only first Class and ignore all others after first space
b. Requires to understand what an elemment.child is
'Example:
'Clicking first child of "div" (Everything inside "div" is a child)
CD.FindElementByCss("div.addToCartButtons > button:nth-child(1)").Click
3) Easiest:
a. Double quotes ["] inside querySelector are changed to single quote [']
b. Requires to use Copy JS path in DevTools (Ctrl + Shif + I)
'Example:
'Clicking with Javascript in your website through ExecuteScript
strTemp = "document.querySelector('div.addToCartButtons clearAfter > button blue right s-addToCart').click"
CD.ExecuteScript (strTemp)

Find this element in this website using Selenium

I have used Selenium in VBA to get to this page and would like to click on the 'WIP Management' Button. However the code that I use says the element is not found. Could someone please help.
This is the part of the website with the inspect panel
This is my code that can't find the element.
If obj.IsElementPresent(By.XPath("//button[text()='WIP Management']")) Then
MsgBox "True"
Else
MsgBox "False"
End If
I can not see the button tag in HTML, try the below locator
//*[text()='WIP Management']
OR
//*[contains(text(),'WIP Management')]
OR
//*[normalize-space()='WIP Management']

Is there a way to click on anchor link

Please help me as the anchor tag looks like the below
<a title ="excel" class="activelink"style="Text-Decoration: none; onclick="$find('ReportViewerControl').exportReport('Excelopenxml');" href ="javascript:void(0)" alt="Excel" _selected="true"> Excel</a>
This doesn't have any document id or class.. Any help would be highly appreciated.
I try to check your HTML code and found that it contains the class but it can be possible that many other elements on the page using the same class. If you try to access the link using that class then it can possible that you click the incorrect element on the page.
We can see that the link contains the ' Excel' text. We can try to loop through all the links on the page and try to match the innerHTML to find that specific link.
Example:
'Below is code to loop through anchor tags, find the specific link, and click it.
Set elems = IE.document.getElementsByTagName("a")
For Each elem In elems
If (elem.innerHTML) = " Excel" Then
elem.Click
Exit For
End If
Next elem
Output:
In a similar way, you can also match other attributes from the anchor tag that may also help to click the link.
Note: This code example is for clicking the specific link on a page. It may not help you to automate the file download.
Further, you can try to modify the code example as per your own requirements.

seleniumIDE - how to store a hyperlinks address and then visit that URL? Was working before

I had this working fine a couple of months ago but now when I run the test it fails and I don't know why or how to fix.
Background:
I have a screen with several links so that the 'admin' user who is currently logged in can login as one of the 'practitioners' via the login hyperlink presented.
Details:
So for my test I click on the 'Login link' hyperlink(s), enter & confirm a new password as required, and then I get to the practitioners screen 'as them'. The 'wrinkle' was that the pop-up for the user to enter their (new) password happened on a new window that the selenium IDE used was a new window. So basically just clicking on the hyperlink didn't work. To get around this I was able to store the hyperlink's href -a#href- in a selenium variable first_login_link_to and then use open instead of clickAndWait to visit the page, i.e. open ${first_login_link_to}
This was working fine a few months ago.... but it is not working now.
I get page doesn't exist and when I look at the url - urgh! It somehow includes the locator stuff and I am getting
http://dmplanning-stage.herokuapp.com//tr[td[contains(.,'6 Day')]][1]/td[8]/a#href
instead of
http://dmplanning-stage.herokuapp.com/p/zaH7m3aL7fxuPLvrc21L
in the browsers url address bar.
How can I get selenium to open the url stored in the variable and not use that 'locator' address?
selenium:
open /admin
clickAndWait link=practitioners
store //tr[td[contains(.,'6 Day')]][1]/td[8]/a#href
open ${first_login_link_to}
Found it - whew! Somehow my storeAttribute got changed to plain store.
Once I changed it back everything worked again!
This one worked for me
1-
Command = Store
Target = stuff you want to paste
Value = Var
2-
Command = sendkeys
Target = id for area where u wana paste
Value = ${Var}
3-
Command = Fireevent
Target = id for area where u wanna paste
Value = paste