Cant change element value Gecko browser (v45) - vb.net

Im trying to change the HTML element value in a gecko browser (v45.0.32) but it is saying invoke member is not a member of gecko element,
For Each solo As Gecko.GeckoHtmlElement In GeckoWebBrowser1.Document.text
If GeckoWebBrowser1.Document.GetElementById("order_status_id").GetAttribute("value") = "1" Then
GeckoWebBrowser1.Document.GetElementById("order_status_id").SetAttribute("value", "2")
If GeckoWebBrowser1.Document.GetElementById("notify").GetAttribute("value") = "1" Then
GeckoWebBrowser1.Document.GetElementById("notify").InvokeMember("click")
GeckoWebBrowser1.Document.GetElementById("button-history").InvokeMember("click")
End If
End If
Next
GeckoWebBrowser1.GoBack()

There is a 'Click()' method available on GeckoHtmlElement, so you can do something like below:
(cast and invoke Click();)
((GeckoHtmlElement)GeckoWebBrowser1.Document.GetElementById("notify")).Click();
Hope this helps.

There is no method called InvokeMember in GeckoHtmlElement, use Click.
The code you have specified should be called only from main thread. Use Invoke on GeckoWebBrowser's parent, if necessary.
To make sure, that one of your elements has an attribute, first check if this element exists in current document, like this:
Dim element = GeckoWebBrowser1.Document.GetElementById("")
If element IsNot Nothing AndAlso element.GetAttribute("value") = "1" Then
element.SetAttribute("value", "2")
End If

Related

Selenium VBA - Runtime Error 11 ElementyNotVisible Error element not interactable

I am using the below mentioned code for automation of Edge Browser
The code is working fine except for "If then Else" block.
The complete script is as follows
Dim Obj As New WebDriver
' search for company - SF 1cr and above
Sub EdgeAutoSF1CRA0()
Set Obj = New Selenium.EdgeDriver
Dim ele As WebElement
Dim By As New Selenium.By
Obj.SetCapability "ms:edgeOptions", "{""excludeSwitches"":[""enable-automation""]}"
Obj.Start "edge", ""
Obj.Get "https://*********************"
Obj.Window.Maximize
Obj.FindElementByName("croreAccount").SendKeys ("Search")
Obj.FindElementByXPath("//*[#id='loadSuitFiledDataSearchAction']/div[1]/div[3]/div[4]/img").Click
Obj.FindElementById("borrowerName").SendKeys (ThisWorkbook.Sheets("Sheet1").Range("C5").Value)
Obj.FindElementByXPath("//*[#id='search-button']/ul/li[1]/div/input").Click
Obj.Wait 30000
If Obj.FindElementByCss("#downloadReport").Attribute("Style" = "display") = "none" Then
Obj.FindElementByXPath("//*[#id='three-icons']/ul/li[3]/a/div").Click
Else
Obj.FindElementByXPath("//*[#id='downloadReport']/div").Click
End If
End Sub
In the If then Else statement I want to search for the style attribute of the id "downloadReport" for "display :none"
The code on website is < a href="downloadStatusReport" id="downloadReport" style="display: none;"><div class="download-icon">Download</div></a>
However, code always evaluate the statement as False and proceeds to execute the command "Obj.FindElementByXPath("//*[#id='downloadReport']/div").Click"
The attribute name is style, not capitalized Style.
You can construct the locator so that the desired style value will be a part of locator itself.
You can use FindElements instead of FindElement so it will return you a list of matching elements so as if such element found it will return a non-empty list, otherwise it would be an empty list. With this you can check if returned list is empty or not, as following:
If Not IsEmpty(Obj.FindElementsByCss("[id='downloadReport'][style*='none']")) Then
Obj.FindElementByXPath("//*[#id='three-icons']/ul/li[3]/a/div").Click
Else
Obj.FindElementByXPath("//*[#id='downloadReport']/div").Click
End If
In short, there is no merit in locating an element with style attribute set as display: none;. Even through you locate the element, you won't be able to click on it. So the If-Then-Else logic won't work as intended.
Instead find the desired element which is visible and enabled element, so you can invoke click on it.

How to edit element in table with selenium?

I'm trying to edit value of element that placed it the table on
this page.
I'm using this code:
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCellTable");
WebElement firstName = driver.findElement(By.xpath("//*[#id=\"gwt-debug-contentPanel\"]/div[2]/div/div[2]/div/div[3]/div/div/div/table/tbody/tr[1]/td/table/tbody[1]/tr[1]/td[2]/div"));
firstName.click();
firstName.clear();
firstName.sendKeys("test");
It says:
"Element must be user-editable in order to clear it."
How i can edit this element?
Also i have troubles with "Category" field on this page. I'm trying to select each of them successively. Doing this with:
WebElement category = driver.findElement(By.xpath("//*[#id=\"gwt-debug-contentPanel\"]/div[2]/div/div[2]/div/div[3]/div/div/div/table/tbody/tr[1]/td/table/tbody[1]/tr[1]/td[4]/div/select"));
category.sendKeys("Businesses");
category.sendKeys("Friends");
category.sendKeys("Coworkers");
category.sendKeys("Businesses");
category.sendKeys("Family");
I tried to make category.sendKeys(""); once and it works well.
But throws this: "stale element reference: element is not attached to the page document" when i get a lot. How i can change this elements one by one?
This is kinda a strange one. The DOM keeps changing which makes it harder to see what's going on so that you can do the right thing to make it work. You have to click one element which changes the DOM and inserts an INPUT which is what you need to .sendKeys() to. I have tested the code below and it works.
I like to create functions for things like this so that they are reusable. This function changes the first name. rowIndex is the row of the table you want to change and firstName is the desired first name. You have to wait for the table to finish loading because it loads dynamically after the page is loaded.
public static void setFirstName(int rowIndex, String firstName)
{
WebElement firstNameElement = new WebDriverWait(driver, 10)
.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("tr[__gwt_row='" + rowIndex + "'] > td > div")))
.get(1);
firstNameElement.click();
firstNameElement.findElement(By.tagName("input")).sendKeys(firstName + "\n");
}
To change the first name of the first row to "FirstName" you would call it like,
setFirstName(0, "FirstName");

How to define By element xpath using another By element using Selenium WebDriver

I want to definde a By element xpath, using previously defined By element.
Example:
I have a following By Element defined:
private By firstExpander = By.xpath("//div[#id = 'language-expander']");
Now I want to define another By element, that is a child in the DOM structure of this element, for example the Name of this 'language-expander'. I have tried following:
private By firstExpanderName = By.xpath(firstExpander.toString() + "/div[1]/a");
but it includes the "By.xpath" part of the parent in the resulting string. And I'm sure I'm doing this wrong. Any suggestion on how to do this properly?
Try this,
String div = "//div[#id = 'language-expander']";
private By firstExpander = By.xpath(div);
private By firstExpanderName = By.xpath(div + "/div[1]/a");
Assign the parent xpath string to a variable. Later you can append any string to that to derive child xpath.
Please try it this way -
private By firstExpanderName = firstExpander.findElement(By.xpath(".//div[1]/a"))
WebElement wb1 = driver.findElement(By.xpath(""));
WebElement wb2 = wb1.findElement(By.xpath(""));
wb2.[YourAction]

Getting HRESULT: 0x800A01B6 Exception while getting elements from InternetExplorerMedium website

I'm trying to make some code on VB.net that opens a website and logs in, and after that runs a report. Everything has been working fine when I try to get any of the from the website, but the ones that have this instruction within the OnClick property = "return oamSubmitForm('inputParamView:paramForm','inputParamView:paramForm:_idJsp106');"
Basically, if you see the following code, you see that I click on some of the CheckBoxes and it works just fine, but when I retrieve the button, it doesn't type an input, it actually has the link of the website when I use a whatc while debugging.
This is my code (I skipped the login section):
Private Sub open Page()
ieb = New SHDocVw.InternetExplorerMedium()
ieb.Navigate("http://example.example/qptheme2/pages/index.faces")
ieb.visible = True
ieb.Silent = True
While Not (ieb.ReadyState = WebBrowserReadyState.Complete)
Application.DoEvents()
End While
If v.checked = False Then
v.Click()
End If
v = ie.Document.GetElementById("inputParamView:paramForm:inputParametertuesday")
If v.checked = False Then
v.Click()
End If
v = ie.Document.GetElementById("inputParamView:paramForm:_idJsp106")
v.Click() '<-- IT FAILS HERE Exception HRESULT: 0x800A01B6
If I check the watch it shows mshtml.HTMLAnchorElementClass {http://example.example/qpreport/savedpages/savedReports.faces#}
if I check the source code from the page, this is the element that I'm trying to get:
<a id="inputParamView:paramForm:_idJsp106" onclick="return
oamSubmitForm('inputParamView:paramForm','inputParamView:paramForm:_idJsp106');" href="#"
I don't know if it has anything to do with the property OnClick.
I will appreciate any of your help trying to solve this issue.
I found the solution by myself. I just had to instance the element I was retrieving as mshtml.HTMLAnchorElementClass
after that, I was able to click on it.
Dim l As mshtml.HTMLAnchorElementClass = ieb.Document.GetElementById("inputParamView:paramForm:_idJsp106")
l.click()

gettext() intelesence is not available in selenium

I have been trying to get the text for the pop up window using the gettext() method, i am unable to get even the gettext() method in the intelesence in the selenium webdriver.
To get anything from a pop up window you have to switch the driver over to the new window:
driver.switchTo().window("WindowName");
You can get the window handles (selenium specific) by calling:
driver.getWindowHandles();
this returns a set of string handles which you can then pass to the switchTo().window() method. Once you are in the desired window you can get the element's text.
you should try this
driver.switchTo().window("WindowName");
String strText = driver.findElement(By.id("id")).getText();
Enjoy!