Skip to content

Instantly share code, notes, and snippets.

@khunreus
Last active April 15, 2020 17:00
Show Gist options
  • Save khunreus/52838ba68affa59e8cb494f764bc0e10 to your computer and use it in GitHub Desktop.
Save khunreus/52838ba68affa59e8cb494f764bc0e10 to your computer and use it in GitHub Desktop.
"""
python3.6
ipython console test
"""
import selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
self.header = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36'}
driver = webdriver.Chrome('path/to/chromedriver')
#home page
search_city = driver.find_element_by_xpath('//*[@type="text"]').send_keys('Dubai h\ue007')
sleep(0.8)
search_button = self.driver.find_element_by_xpath('//*[@type="submit"]')
search_button.click()
sleep(8.7)
#homes vs experiences page
homes_button = self.driver.find_element_by_xpath('//*[@data-veloute="explore-nav-card:/homes"]')
homes_button.click()
sleep(4.2)
#catalogue page with an
#infinite scroll
last_height = self.driver.execute_script("return document.body.scrollHeight")
SCROLL_PAUSE_TIME = 7
while True:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
sleep(SCROLL_PAUSE_TIME)
new_height = self.driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
last_height = new_height
sleep(1.2)
@demisx
Copy link

demisx commented Apr 15, 2020

I am not clear why the first line is not using self. and the third one does. Could you please clarify?

...
search_city = driver.find_element_by_xpath('//*[@type="text"]').send_keys('Dubai h\ue007')
sleep(0.8)
search_button = self.driver.find_element_by_xpath('//*[@type="submit"]')
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment