VBA Selenium Date Selector in iframe - vba

I am trying to select a date but currently struggling. This date selector is in a iframe. I have switched to iframe but no nothing works to select the date, I have trying to change the data in this value part but it still does not work. I used the CSS, Xpath, ID, Class but nothing works.
.
I have found that using the Xpath is work for all the other elements like selecting time and dropdown.
With obj
'open edge
.Start "edge"
End With
'declare URL
Dim url As String
url = "http://cogprodweb.co.za"
'nagivate to url
obj.Get (url)
With obj
'Wait for frame to load and then Select the iframe
Application.Wait (Now + TimeValue("0:00:02"))
.SwitchToFrame ("iC93CD3A10B5343779D27E431CE7AF966")
'Select Locations
.FindElementByXPath("/html/body/form[1]/table/tbody/tr[2]/td/div/div/table/tbody/tr[2]/td/div[2]/table/tbody/tr/td[2]/div/select/option[9]", 3000).click
'Select Date
.FindElementByXPath("/html/body/form[1]/table/tbody/tr[2]/td/div/div/table/tbody/tr[2]/td/table/tbody/tr[3]/td[1]/div/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td[1]/input", 3000).SendKeys("2021-07-19").click
I through identifying the calendar (which is table) and them running from the cells until it equal to inputted value (yesterday). I am not sure what do you for that. The variables, I have been looking at has not been working out. Looking at this to.
Iterating Through Table Rows in Selenium (Python)

it looks like the id of the iframe is being regenerated and the locator you're using might be no good i.e:
.SwitchToFrame ("iC93CD3A10B5343779D27E431CE7AF966")
either use a solid locator (add an id to the iframe element in html) or use a different locator meanwhile.
you can debug this and try to grab the iframe element with the id that was generated and see if indeed it's the locator issue or not

Related

How to get sub div in the loop in Selenium?

I am attempting to scrape the website
https://justjoin.it/
I want to get all texts inside every job offer.
To get links to job offers I am using Xpath:
Dim elems as Selenium.WebElements
Set elems = mw.FindElementsByXPath("//div[contains(#class,'css-ic7v2w')]/div/div/div/a)
For Each webele In elems
Debug.Print webele.Attribute("href")
Debug.Print webele.Text
Next webele
and it is working fine.
The issue is that I want to go deeper into each specific div (3 divs after) and get the "alt" attribute which is the job offer name.
How to make this work? I suppose it will be some kind of sibling element?
I tried to loop through each webelement and get the siblings of it but I failed.
So what i want to get is to find specific div and loop through next nested divs inside.

VBA automation can't get innerText (innerHTML, value)

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;")

Get text associated with check box in selenium where html code does not have value or name property

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");

Selenium WebDriver and xpath locating inside WebElement

I have a page containing multiple forms with their own submit buttons and other elements. While testing the page, I locate the second form
WebElement form = getDriver().findElement(By.id("form2"));
and then field and submit button
form.findElement(By.name("text")).sendKeys("Adding some text here");
form.findElement(By.xpath("//input[#type='submit']")).click();
However these xpath locations take effect on the first form. Is it really so that the xpath doesn't work inside a specified element?
Try a relative path:
form.findElement(By.xpath(".//input[#type='submit']")).click();
In fact Selenium works with the first found by xpath element. If you know exact order number you can add such a number to your xpath //input[#type='submit'][2]. Please note that numbering in xpath starts from 1 but not 0. So given xpath will found for you the second input with #type='submit'.

How to manipulate user selected text using webdriver?

Lets say i have the following snippet in my web page:
<p> This is some text </p>
I want WebDriver to select "some" in this text, as if the user selected it. How should i do this? I know how to get the <p>-element:
WebElement editable = getDriver().findElement(By.id("someId"));
editable = editable.findElement(By.tagName("p"));
System.out.println(p.getText());
The println prints "This is some text".
I tried sending keys to the element, and that used to work(in selenium 2.0b), but i'm using selenium 2.6.0 now, and it stopped working:
editable.sendKeys(Keys.chord(Keys.SHIFT, Keys.LEFT));
Does anyone have ideas? I'm using the FirefoxDriver.
I did this once for Firefox using Javascript. Basically I used the range object in Firefox to select the text. Change the start and end range index based on what you want to select. This would not work in IE, because selecting range is conceptually different in IE. I don't have the IE code handy but since you are concerned about FF, you could give this a shot.
Let me know if you interested in IE text range.
String script = "var range = document.createRange();" +
"var start = document.getElementById('idofthedivthatcontainstext');" +
"var textNode = start.getElementsByTagName('p')[0].firstChild;" +
"range.setStart(textNode, 8);" +
"range.setEnd(textNode, 13);" +
"window.getSelection().addRange(range);";
((JavascriptExecutor)driver).executeScript(script);
You are trying to select the contents of the p tag by drag select right I am not sure if that is objectively possible to be done by the user as your are suggesting.. Selenium now tries to mock the exact action that a user can perform on a browser. thus you just cant send a shift and left select key on the p tag and expect it to select unlike a textbox where it is very much possible but you might probably have to click on the text box first to get it into focus.
Here is what I would suggest to achieve this, not sure if it will work.
a) send the left click on the p tag
b) hold the shift key
c) drag the mouse to the end of the p tag.
Hope that helps.
Use the .Text property of the IWebElement
WebElement editable = getDriver().findElement(By.id("someId"));
editable = editable.findElement(By.tagName("p").Text).ToString();
editable.Replace("This is ", "").Replace(" text.");
System.out.println(p.getText());