Python Forum

Full Version: Need help in selenium
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I need help
I want to scroll down my page so the page can be sumbitted
It seems that the page cannot view submit_input_id = "side-contact-submit" so the page cannot be auto submitted

import requests
import csv
import sys
import os
import sys
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options


def auto_contact_agent(url):
    #url="https://www.srx.com.sg"+url

    chrome_options = Options()
    #chrome_options.add_argument("start-maximized")
    chrome_options.add_argument("--window-position=05,10")
    chrome_options.add_argument("--window-size=1920,1080")
    chrome_options.add_argument("--window-scrollTo=10, 150")
    driver = webdriver.Chrome(chrome_options=chrome_options)
    driver.get(url)
    import time
    #time.sleep(30)
    name_input_id = "side-contact-name"
    email_input_id = "side-contact-email"
    mobile_input_id = "side-contact-mobile"
    submit_input_id = "side-contact-submit"
    #submit_input_id = "listing-contact-submit"

    elem = driver.find_element_by_id(name_input_id)
    elem.clear()
    elem.send_keys("Rob")


    elem = driver.find_element_by_id(email_input_id)
    elem.clear()
    elem.send_keys("[email protected]")

    elem = driver.find_element_by_id(mobile_input_id)
    elem.clear()
    elem.send_keys("1234567")

    #elem = driver.find_element_by_id(submit_input_id)
    #elem.click()


    time.sleep(10)
    driver.close()



url="https://www.srx.com.sg/listings/77777052/for-sale-hougang-avenue-6-5mins-to-hougang-mrt-above-7th-floor"
auto_contact_agent(url)
You can use a function like this to scroll down

	def scroll_to_bottom():
	    SCROLL_PAUSE_TIME = 0.5
	    # Get scroll height
	    last_height = driver.execute_script("return document.body.scrollHeight")

	    while True:
            # Scroll down to bottom
            driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

            # Wait to load page
            time.sleep(SCROLL_PAUSE_TIME)

            # Calculate new scroll height and compare with last scroll height
            new_height = driver.execute_script("return document.body.scrollHeight")
            if new_height == last_height:
                break
            last_height = new_height