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
Related
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.
So, i've gotten innertext many times. This time, it's simply not working. Tried many alternatives.
First of All
I'm using Selenium on VBA to use chromedriver.
The source website is "[http://www.fazenda.df.gov.br/area.cfm?id_area=1536]" This website operates on a Iframe. After half an hour trying to get the inner text from it, i figured that the link in its code works just as fine: "[http://publica.agnet.fazenda.df.gov.br/FichaImovel/#/FichaCadastral]". This last one seems to operate on someting call "Angular".
The menu with the innertext i required is a dropdown one. As a dummy value, you can use 50868748. The dropdown text that it generates is composed by 15 lines and one table. The info that i need is on the 15th line, "Nome do Responsável", or in the column 2 line 2 on the table.
I managed to place the code and generate the dropdown list, but i can't manage to get the inner text.
Here is my code:
Dim iptu As String
Dim driver As New ChromeDriver
With driver
.Start
iptu = 50868748 'dummy
.Get "http://publica.agnet.fazenda.df.gov.br/FichaImovel/#/FichaCadastral"
.FindElementById("inscricaoImovel").Clear
.FindElementById("inscricaoImovel").SendKeys iptu
.FindElementsById("btnCadastro")(2).Click
.Wait (300)
'until here, everything works fine
Dim label As Object
Dim name As String
Set label = .FindElementsByClass("ng-binding")(91)
'as you can see, i end up using this class(91) to get the value on the table, but i can get from the 15th line too
name = label.getAttribute("innerText") 'Error is here
'i've tried .innerText, .innerHTML and others. The error is always "object does not accept property or method" Error 438.
end with
The chrome driver is up to date. Also, the page source does not cointain the info i need.
Anyone can help me out?
To get InnerText of the element, You need to call Text method
Set label = .FindElementsByClass("ng-binding")(91)
name = label.Text
To get inner Html,
name = label.Attribute("innerHTML")
Sometimes I have found that I have to execute javascript to get what I'm after. You can try
name=driver.ExecuteScript("document.getElementsByClassName('ng-binding')[91].innerText;")
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")
So i am trying to get some text from a web page that is located between tags. I have included an image that shows the text i am trying to get.
highlighted text
the code i have currently is as follows although it is gathering other information as well which is not needed.
For Each ele As HtmlElement In WebBrowser1.Document.All
If ele.GetAttribute("className").ToLower.Contains("cwybtn") Then
Dim colourSource As String = ele.GetAttribute("innerText")
'ListBox2.Items.Add(colourSource) 'Adds all .jpg images to the ListBox
MsgBox(colourSource)
End If
Next
Has anyone got any ideas
why don't you try with tagName? you have an element from class name try to get the element from that element as tagName
hope this will help getElementsByTagName("strong")
Ankit
thanks for that! I for got about tagname to be honest, i have now fixed it!
For Each strongTag As HtmlElement In WebBrowser1.Document.GetElementsByTagName("strong")
MsgBox(strongTag.InnerText)
Next
I have a Radcombobox in my application which has several check boxes in the combo box. What I wish to do is to fetch the text associated with the check box. I searched on internet and came to know that text can be fetched from name or value property in HTML code, but problem is that my HTML code does not have such properties.
HTML code:
input class="rcbCheckAllItemsCheckBox" type="checkbox"
Check All
What i wish to do is to fetch value "Check All".
Using code x = driver.findElement(By.xpath("/html/body/form/div[1]/div/div/div/input")).getText();, value returned is blank.
You can get the text through JavaScript API of Rad Controls. You can check the official documentation- http://docs.telerik.com/devtools/aspnet-ajax/controls/combobox/client-side-programming/overview
Basically, you first locate the element in JS and then use the official control method, in your case get value method. You can also perform several other useful operations if you need to.
You can execute JS in WebDriver with the following code:
IWebDriver driver;
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
string title = (string)js.ExecuteScript("return document.title");