Reputation: 35
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"
Upvotes: 0
Views: 274
Reputation: 193058
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.
Upvotes: 0
Reputation: 33353
style
, not capitalized Style
.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
Upvotes: 0