Python Web Scraping with submission of Select and Radio Button - python

I am interested in getting a python script so as to visit the url"https://www.ura.gov.sg/realEstateIIWeb/resiRental/search.action#district", click on the tab "Search by property type and postal district" and finally choosing the parameters for:
Select the Date of Lease Commencement: "Sep-14" to "Aug-2017"
Select the Property type (radio buttons): "Landed properties"
Select the Postal District (i want to iterate and select all, but there is a limit of 5 at a time, hence ideally there should be a loop of 5s each time)
before submitting "Search".
After pressing search, the python script should click on "Download into CSV".
THe main problem i am facing is that i am not sure how to Click on Tabs or get python to fill up the "Select" and "Radio" buttons.
Any help is greatly appreciated.
Thanks!

Related

how can i select value from react dropdown using selenium python?

I am doing website testing in selenium python. I am not able to select a value from the dropdown. Can anyone help me to do that?
This is my website source code.
when expanding dropdown it does not show value in the DOM so how can I select state Alaska?
As per the attachment, text box accepts input and filters dropdown list based on our input..To handle these cases:
You can use Actions class to handle this.
Actions(driver).click(element).sendKeys("Alaska").sendKeys(Keys.ENTER).perform();
Here, we are communicating with search box cum dropdown and entering "Alaska" in it. Once it entered, it filters the results and display only Alaska in the dropdown.
Later Keys.ENTER just performs ENTER operation which will select the first record in the dropdown list.
Use text to identify WebElement. First click on dropdown and write generic xpath like '//*[text()='Alaska']'. This solution may or may not work. But solution 1 is recommendable..

How to select reCAPTCHA?

Dear Stack Overflowers,
I have a short Python script that automatically goes through the Texas Unemployment Website and fills out all of your information every 2 weeks. This year they started implementing a reCAPTCHA. This steps prevents the script from getting to the next step.
I've tried selecting the captcha by ID and Class but haven't had any luck. The class name changes when you hover over the box as well which makes things more difficult. The first picture below is when I'm not hovered over the box and the second picture is with the mouse over the box.
I've been using Selenium in Python to find elements on the webpage and make clicks. Here's my last attempt using class name:
driver.find_elements_by_class_name('recaptcha-checkbox goog-inline-block recaptcha-checkbox-unchecked rc-anchor-checkbox').click()
Anybody have any ideas for selecting the reCAPTCHA?

Can't scrape data from webpage with popup/frame

I am having trouble finding elements on a customer-facing webpage that I am scraping data from, using Robot Framework + Selenium. My trouble, I think, has to do with the desired data existing in a popup/frame. The data I seek is located on a customer's invoice, which pops up when I press a button ("View Current Invoice"). I've been successful with logging into the site and navigating around, and at one point I was successful pressing the View Current Invoice button to cause the invoice to pop up - but forgot to commit that code and lost it. :-(
In any case, eve if I manually enter the popped up invoice by pressing the button when my script is expecting it to be pressed, I can't seem to scrape the subsequent data. I have tried to identify elements on the invoice using locators (from Right-Click-Inspect capability built into Firefox and Chrome; Katalaon Recorder; Selenium IDE; etc.). I get what looks like a valid locator (almost always Xpath); yet when I run my Robot script, it fails to find the element in question. I have spent a lot of time poring over the page's source code, but since I am not as savvy with HTML/JS/CSS as I should be, I haven't been successful.
Here is a screenshot of the invoice button:
And here is what I see when the button is pressed. I want to scrape all the invoice data, like Amount Due, Invoice Number, Due Date, etc.
Does anyone have any idea what I am missing here? What would you do to get the data on the invoice if you were in my shoes? I know my question probably sounds vague and naiive, but I am at the end of my rope, so to speak. I am willing to share page source code, more screenshots, whatever is required.
EDIT I used Rahul Rai's method to inspect the popup while it was popped up; then searched for "iframe". There were 10 matches; #7, when clicked on, resulted in the invoice popup being highlighted in blue:
I assume this means this is the iframe referencing the popup? If so, I should be able to find information about the "handle" to the iframe in the inspection code, but I don't see anything there that matches the locators I am used to (e.g. name, id, xpath). I even tried "Select Frame 1599252503952", but that just resulted in a
"Element with locator '1599252503952' not found" error.
As per above screen you have shared I can see your Invoice details are inside iframe. So after clicking on View Current Invoice button you can use below code to navigate inside frame and then scrape required information.
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[contains(#src,'invoice_detail_container']")))
#Code to scrape data
ele = driver.find_element_by_xpath('<xpath>')
print(ele.txt)
......
......
#After your work is done in this frame to navigate back to main window
driver.switch_to.default_content()
Note: I have assumed your main frame for invoice is not in side any other iframe ( Based on screen shared). Also before elements start there is no other nested frame. If there is any other nested frame you need to navigate first into that.
I was finally able to scrape data from the Invoice popup after inspecting the HTML source, and seeing this:
<iframe frameborder="0" src="/cmc/invoice_detail_container.pyt?direction=//my.hughesnet.com/cmc/invoice_detail.pyt%3Finvnumber%1234-567890&portletId=863" name="1599391562960" class="cboxIframe" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"></iframe>
I was then able to use the Select Frame keyword in Robot Framework, specifying the iframe locator for the popup, using the 'class' strategy. I also had to explicitly select the main body frame first. In the end, the code that allowed me to enter the iframe and scrape was:
Select Frame body
Select Frame class:cboxIframe
Big thank you to Rahul Rai for pushing me closer to the solution; and thanks to the others who answered as well.
You need to switch your site to frame/popup, you can use like below example, may be it will help you.
IList<IWebElement> textfields = new List<IWebElement>();
textfields = driver.FindElements(By.TagName("iframe"));
driver.SwitchTo().Frame(textfields[count); // number of textfields list.
please try to implement as per your scenario, let me know if any question.
You can try to do :
driver.switch_to_active_element()
and then scrape the popup to close it. Then I think it will be okay...

Need help hovering over a dropdown list and selecting a specific dropdown option (Selenium, Python)

This is my first post so bear with me. I'm trying to go into a dropdown list (Products) that is located in a toolbar at the top of the webpage. Once hovering over the dropdown Products, I'd like to click the one that is named ModMaster so I can navigate to the link 'https://www.modmaster.com'. How do I go about doing this?
I've tried several different methods but the core issue is that's unable to locate the element. If I explicitly wait for it to be visible, it times out.
I've tried using Select, javascript execute, simple find_by_element.click to no avail.
Really the end result just needs to be the current webpage needs to change into www.modmaster.com and keep me logged in. I appreciate any help!
Here is the HTML:
`<ul class="topbar-module-wrap"><li class="topbar-module"><div class="login-info dropdown"><span>Welcome, hidden</span><ul class="dropdown-menu"><li><label>User name:</label> hidden</li><li><label>Agency:</label> hidden</li><li class="divider"></li><li>Log out</li></ul></div></li><li class="topbar-module"><div id="product-dropdown" class="product-menu dropdown"><i class="icon-menu-white-small"></i><span>Products</span><ul class="dropdown-menu"><li><div class="topbar-product-name">Account Management Center</div><div class="topbar-product-subtext"></div></li><li><div class="topbar-product-name">Broker Briefcase®</div><div class="topbar-product-subtext">Sales and Marketing Platform</div></li><li><a href="https://www.modmaster.com/" target="_blank"><div class="topbar-product-name">ModMaster®</div><div class="topbar-product-subtext">Mod Analysis Tool

Scrape a website with interactive buttons

I am totally new into scraping a website.
I am trying to download the tables from https://www.ssa.gov/oact/NOTES/as120/LifeTables_Tbl_7.html
The way we use the website is to select a year from the button and press "Go", then a table for the selected year presented and I want to save the table.
I guess there should be a way to simulate human to select the year, for example, automatically select 1900 then press "go" , then loop for 100 times to record table from 1900 -2000. But I don't know how to simulate this human action.
I have know how to download the table once it is presented, but I just don't know how to let the table presented.
Thanks!
https://www.ssa.gov/oact/NOTES/as120/LifeTables_Tbl_7_**1950**.html
https://www.ssa.gov/oact/NOTES/as120/LifeTables_Tbl_7_**2030**.html
Like you see the only thing that changes is the year. So when you go to scrape a website. you need to scrape https://www.ssa.gov/oact/NOTES/as120/LifeTables_Tbl_7_" + TheYearIWant + ".html

Categories