Need help in selenium - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Need help in selenium (/thread-6132.html) |
Need help in selenium - Lizard - Nov-07-2017 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) RE: Need help in selenium - metulburr - Nov-07-2017 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 |