Reputation: 96
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
class Instabot:
def __init__(self,username,password):
self.driver=webdriver.Chrome("/Users/Aleti Sunil/Downloads/chromedriver_win32/chromedriver.exe")
self.driver.get("https://www.instagram.com/")
sleep(2)
self.driver.find_element_by_xpath("//input[@name=\"username\"]").send_keys(username)
self.driver.find_element_by_xpath("//input[@name=\"password\"]").send_keys(password)
self.driver.find_element_by_xpath("//button[@type=\"submit\"]").click()
sleep(10)
self.driver.find_element_by_xpath("//button[text()='Not Now']").click()
self.driver.find_element_by_xpath("//a[contains[@href,'/{}')]".format(username)).click()
usrlink = "https://www.instagram.com/"+username+"/"
self.driver.get(usrlink)
self.driver.find_element_by_xpath("//a[contains(@href,'following')]").click()
self.driver.execute_script("window.scrollTo(0,500)")
sleep(20)
Instabot('sunil_aleti','password')
I'm unable to scroll that dialog box, so i couldn't get that followers list Plz help me
Upvotes: 0
Views: 2303
Reputation: 978
This is a worse practice in selenium (Please check seleniumhq site)
For multiple reasons, logging into sites like Gmail and Facebook using WebDriver is not recommended. Aside from being against the usage terms for these sites (where you risk having the account shut down), it is slow and unreliable.
The ideal practice is to use the APIs that email providers offer, or in the case of Facebook the developer tools service which exposes an API for creating test accounts, friends, and so forth. Although using an API might seem like a bit of extra hard work, you will be paid back in speed, reliability, and stability. The API is also unlikely to change, whereas webpages and HTML locators change often and require you to update your test framework.
Logging in to third-party sites using WebDriver at any point of your test increases the risk of your test failing because it makes your test longer. A general rule of thumb is that longer tests are more fragile and unreliable.
WebDriver implementations that are W3C conformant also annotate the navigator object with a WebDriver property so that Denial of Service attacks can be mitigated.
Upvotes: 1
Reputation: 133
To scroll the list down use the below code. If it's not working change the xpath to match the parent div of the list.
followers_panel = browser.find_element_by_xpath('/html/body/div[5]/div/div/div[2]')
browser.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight",followers_panel)
Upvotes: 1
Reputation: 11
Use this code it may help you.
wait = WebDriverWait(self.driver, 15)
wait.until(lambda d: d.find_element_by_css_selector('div[role="dialog"]'))
# now scroll
driver.execute_script('''
var fDialog = document.querySelector('div[role="dialog"] .isgrP');
fDialog.scrollTop = fDialog.scrollHeight
''')
Upvotes: 1