Is there a way to click on anchor link - vba

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.

Related

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']

Selenium Webscraping - Print element that is not visible on the site but its on Inspect

enter image description here
I'm trying to print this 91040 from the site but I can't seem to do it and I think the reason is that 91040 is not visible on the site but only on inspect.
element = driver.find_element(By.XPATH,'//div[#class="code-container"]//span[2]')
When I paste this XPATH in the find bar on Inspect it locates the item but when I'm trying to print the element nothing gets printed. I tried these options.
print(element)
print(element.text)
So I'm thinking that the problem is that 91040 is not an actual visible text.
For anyone having the same problem I found the answer
hidden_text = element.get_attribute("textContent")

How to open href link in chrome to VBA?

Its my first time using VBA.
Apparently i need it to help me edit the available stocks from various products (gonna need to learn about looping) and that various products left me with different href stocks edit link
Is it possible to click on the href link and open it ?
heres the element
heres the vba script
Sub AutoFill()
Dim obj As New WebDriver
obj.Start "chrome", ""
obj.Get "https://siplah.blibli.com/login/merchant"
obj.FindElementById("txt-email").SendKeys (ThisWorkbook.Sheets("Pass").Range("E20").Value)
obj.FindElementById("txt-password").SendKeys (ThisWorkbook.Sheets("Pass").Range("F20").Value)
obj.FindElementById("btn-login").Click
obj.Wait (500)
obj.FindElementByClass("modal-footer").Click
obj.FindElementById("menu-product").Click
obj.FindElementById("txt-product-name").SendKeys (ThisWorkbook.Sheets("31 CV").Range("E4").Value)
obj.FindElementById("btn-search-product").Click
End Sub
Thank you before!
Combining an attribute = value css selector with ends with operator to target href by the end if its href value, along with adding in the element className should be sufficient
obj.FindElementByCss(".link[href$='Slip']").click
Read about css selectors here: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors

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

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

How do I create a logic for href followed by text

Passed
How do I find the element based on the text followed by the href?
I have tried this
IWebElement ele = Driver.driver.FindElement(By.XPath("//a[contains(#href,'grdCoverageSelected' and text(),'Passed']"));
ele.Click();
Also, there are some other controls like
Passed,TBD,Pending,and failed
Also, need to implement a logic if I find passed then it will go to next page and if I will find any other of the tags then it will click the hyperlink and change from TBD to PAssed or failed to passed or pending to passed from the drop-down list
Please try with below solutions.
using xpath = //a[#href='href url'][contains(text(),'text')]
using css = div:contains("Click here") or div>.className:contains("Click here")