Excel Selenium VBA: Dismiss Web Selenium Pop-Up Alert - excel

Steps:
Base URL: https://rivcoview.rivcoacr.org/#/Property-Search
Select the dropdown ""
Enter 609542017 in the Text Box
Click "GO" Button
When I am automating the above single action with a list of numbers and a loop. This Popup Alert occurs when I run a loop of PIN Numbers through, automating the "GO" click, then scaping the output page results. I am trying to dismiss the resulting popup.
No doubt, they have it triggered by some java in the background that detects my automation. I have seen several python or java possible solution examples for my problem that I can not translate to Excel VBA with Selenium. So I need a pure EXCEL VBA Selenium Solution.
CSS Selector for "X" button on the pop-up **= "#surveyModal > div > div > div.modal-header > button"
Tried:
MyBrowser.SwitchToAlert.Dismiss
Set CloseButton = MyBrowser.FindElementByCss("#surveyModal > div > div > div.modal-header > button").click

I am still happy to get suggestions on VBA Selenium PopUps, but I have solved my problem. My Issue ended up not being a pop-up problem. The Element was in the DOM all along as a hidden object. So the following code solved my problem:
Set SurveyButton = MyBrowser.FindElementByCss("#surveyModal")
If MyBrowser.FindElementByCss("#surveyModal").IsDisplayed Then
SurveyButton.Click
Else
GoTo 600
End If
600
'*******************************
I would use this as an alternative to test if the object was created. However, since it was present but hidden all along, the code below won't work and will cause an error.
Set SurveyButton = MyBrowser.FindElementByCss("#surveyModal")
If Not MyBrowser.IsElementPresent(By.Css("#surveyModal")) Then
SurveyButton.Click
Else
GoTo 600
End If
600

Related

Clicking a Hyperlink Selenium & Python

Apologizes for the daft question, but really need some assistance
I have recently started to learn python and found some useful tips online:
on how to populate an ID into a field (reference field)
Select a "firms" = true
and also click "search"
Code Snippet below
driver.find_element(By.XPATH,'//*[#id="search-form-search-section-main-input"]').send_keys(cid)
button1 = driver.find_element(By.XPATH,'//*[#id="search-form-search-options-radio-group"]/span[1]/label/span[1]')
button1.click()
button = driver.find_element(By.XPATH,'//*[#id="search-form-form"]/div[2]/div[2]/div[2]/button')
button.click()
print('Search Result Returned')
These values are being passed in the screen shot below;
[
However i am stuck on the next sequential step.
Once all the steps above are completed, it takes me to the following URL: https://register.fca.org.uk/s/search?q=309238&type=Companies
What i would like to do is click on the tile, so that the next page can load (where I can scrape data)
NB : Regardless of where you tick on the tile it takes you you to another page. ( I assume the it’s a hyperlink)
Whilst viewing that page in chrome it appear that this is the section that refers to that "Title"
and the xpath way is //*[#id="firm-result-card-0"]/div/div[1]
However i tried to reference that in my code, and keep getting errors.

selenium no such element error element not found for excel

I know this has been asked many times, I apologize for that. but i couldn't solve the problem.
I need to export data from excel to chrome web page. but when I press a button on the web page, the small screen opens and I can't find what I'm looking for there.
to be more specific, this is the page I opened. here I click on the button marked red.
enter image description here
A screen like this opens. I need to add data here.
enter image description here
my selenium code is like this.
Public Function kursiyergiris()
Dim tc As Integer
Dim Findby As New Selenium.By
Dim tcekle As Selenium.WebElement
bot.SwitchToNextWindow
Set tcekle = FindElementById("txtTCKimlikNo") // the part where i got the error
tcekle.SendKeys ("12345678")
note: when I search, I can see the "txtTCIDID" part.
thank you for the help.
1: https://i.stack.imgur.com/SXE4T.png
2: https://i.stack.imgur.com/SjnPb.png
Actually "bot.SwitchToNextWindow" is not for the mini window in the 2nd picture. for another window, the login screen. The screen that opens does not have a name. div has name. With the code "Debug.Print bot.IsElementPresent(Findby.ID("RadWindowWrapper_ctl03"))" I can see the div. but I need to write "txtTCIDID" in it.
The 1st photo below is the main screen. The screen where I want to save the second photo. Could you please review it.
enter image description here
enter image description here
It could be that the code bot.SwitchToNextWindow is not switching to the popup window.
Can you replace that code with bot.SwitchToWindowByTitle "{title of the popup window}" and see if that works?

Python- selenium webdriver is not able to find these buttons on modal window

Not able to click x or continue to flights
Here is the url: https://www.kayak.com/flights/ORD-JFK/2020-09-13/2020-09-20?sort=bestflight_a
using css = '.Button-No-Standard-Style.close-button'
I was using the following to find and click it:
driver.find_element_by_css_selector('.Button-No-Standard-Style.close-button').click()
What I found out was the button had dynamic ID. I had to click the button based on partial ID comparison.
I used:
cl_bt = driver.find_element_by_xpath("//*[contains(#id, 'covid-loading-dialog-close')]")
where 'covid-loading-dialog-close' was the part of the ID that was not changing.

Get text from alert message from web with Selenium and VBA

I am currently creating an automation to fill-in field in the browser (Chrome) with VBA and selenium. Which is currently doing fine. (the site is internal)
However, I came across with this "message from web" prompt after saving / submitting the information. Sometimes, this pop-up box gives me a prompt that it was saved successfully and sometimes, if there are errors, the message box contains some text.
In order for me to handle this pop-up message box and put some validation. In this case, I would like to get the text inside this message box. (Please refer to the red arrow).
The code below is what I used in order to accept / click the "OK" button. And doesn't have any problems. However, as mentioned, I would like to get the text inside that box to put some validation.
What I tried so far:
driver.SwitchToAlert
driver.SwitchToAlert.Text <<<--- this is where I attempt to get the text however, it doesn't work.
driver.SwitchToAlert(20).accept
Also, I have check below code:
driver.switchTo().alert().getText();
However, this seems not to be working in VBA / selenium.
Try such a code (Change to suit your issue)
Dim bot As Selenium.ChromeDriver
Sub Test()
Dim dlg As Selenium.Alert
Set bot = New Selenium.ChromeDriver
With bot
.Get "http://the-internet.herokuapp.com/javascript_alerts"
.FindElementByCss("#content > div > ul > li:nth-child(2) > button").Click
Set dlg = .SwitchToAlert(Raise:=False)
Debug.Print dlg.Text
.Wait 2000
dlg.Dismiss
End With
End Sub

Unable to automate selection of List-box option using Selenium and Python

I have been trying to use Selenium and automate book cataloging on this software called Koha. As part of the process, I need to necessarily select an 'item type' from a drop down menu (image attached)
Koha drop-down
Now, I have tried multiple ways to go about this but all have failed:
Using find_element methods to click on the drop down and select an
option - The options in the drop down are captured as empty elements for some reason (snippet of page source code attached)
Source code of drop-down
Code used:
itemElem = browser.find_element_by_xpath("//select[contains(#id,'tag_942_subfield_c')]")
opElem = itemElem.find_elements_by_tag_name('option')
print([op.text for op in opElem])
print([op.value for op in opElem])
print([op.id for op in opElem])
Result of print statements:
['','','','','','','']
Execute JavaScript queries to interact with DOM - I am able to click on the drop down but a search for the list box elements returns an error (images of HTML code for page)
For drop-down,
Drop-down options
Code used:
java_script = "document.getElementsByClassName('select2-choice')[2].click();"
browser.execute_script(java_script)
javaScript = "document.getElementsByClassName('select2-result-label')[5].click();"
browser.execute_script(javaScript)
Result of code:
Error occurred while filling in MARC fields.
Message: TypeError: document.getElementsByClassName(...)[5] is undefined
Anything else I could possibly try? Let me know if sharing more of the HTML code might help.

Resources