Scrolling through list using selenium Python till end - python

I'm trying to scroll through my facebook friendlist / chatlist using selenium webdriver via python but it only scrolls web page and not that list.
I tried something like this:
list = driver.find_elements_by_xpath('xpath')
hover = ActionChains(driver).move_to_element(list)
hover.perform()
But nothing happened!
Can anyone please share how it can be done.

Use a for loop.
Say:
for element in list:
hover = ActionChains(driver).move_to_element(element)
hover.perform()

Related

how to scroll item inside webelement using python selenium

we know how to scroll page with selenium like by calling execute
driver.execute_script("window.scrollTo(0, document.body.scrollHeight-600);")
but let say i want to scrollenter image description here
you can see in the image above that what I want to achieve is to scroll that orange scroll bar so all my contact can be loaded and then I scrape the info which I need it is needed in many websites where data is inside some scroll view like WhatsApp contact list. so how I achieve automatic scrolling with python selenium I try
driver.execute_script("document.getElementsByClassName('nano-slider')[3].scrollTop=100;")
from selenium.webdriver.common.action_chains import ActionChains
action = ActionChains(driver)
slider = driver.find_elements_by_class_name("nano-slider")[3]
action.move_to_element(slider).click_and_hold().move_by_offset(0,100).perform()
as I see during the writing of this question scroll comes exactly what I need to scroll with python selenium automation

Scroll down when the Scrollbar has no tag with Selenium for python

I wanted to scroll down in an element, where the scrollbar doesnt have a tag/element. I did quite a few research on this but i couldnt find anything for that specific case. Im using Selenium for Python
We are talking about the Site "www.swap.gg", its a site for csgo skins, and in order to load every item from the bot, you need to scroll down in the element "Bot inventory". The Site looks like this when using F12 in browser it looks like this The respective element
There is no key which you can use to scroll down there, therefore the .send_keys() command doesnt work by any chance. I also tried the touchactions.scroll_from_element(element,xoffset,yoffset) but didn't have any luck either. Im using Firefox as a webdriver incase that matters.
The xpath of the element is "/html/body/div/div1/section1/div[2]/div[3]/div[2]/div[2]"
The CSS selector is "div.is-paddingless:nth-child(3)"
Any ideas?
Find the parent div
element = driver.find_element_by_xpath('/html/body/div/div[1]/section[1]/div[2]/div[3]/div[2]/div[2]')
Scroll down to trigger the reload
driver.execute_script("arguments[0].scrollBy(0, 500)", element)
import selenium
import selenium.webdriver
import time
driver = selenium.webdriver.Chrome()
driver.get('https://swap.gg/')
element = driver.find_element_by_xpath('/html/body/div/div[1]/section[1]/div[2]/div[3]/div[2]/div[2]')
for i in range(20):
driver.execute_script("arguments[0].scrollBy(0, 500)", element)
time.sleep(2)

Multiple Scroll Bars in Python Selenium

I want to scroll the left nav bar (which shows the job list) to the bottom using python, selenium and chromedriver. I tried using:
_driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
But nothing happened. I'm new to web automation, please let me know if you need anything.
P.S. Page source
This is the last element job list in the left nav bar:
(//li[contains(#class, 'PaEvOc')])[last()]
To achieve scroll to bottom left nav use .location_once_scrolled_into_view:
element = driver.find_element_by_xpath("(//li[contains(#class, 'PaEvOc')])[last()]")
element.location_once_scrolled_into_view

Scroll on a specific DIV Element in Python Selenium

I'm trying to do a simple Python Selenium automation where the script will click a link which opens a dialog box on top of the page (Instagram profile).
The said dialog box will display the list of followers but unfortunately the UL that contains the list will only display the first 12 followers (or LI). It is powered by AJAX to "load more" followers.
Anyway, to simulate loading more followers, i tried this code:
driver.find_element_by_xpath('/html/body/div[3]/div/div[2]/ul').send_keys(Keys.END)
or
driver.find_element_by_tag_name('body').send_keys(Keys.END)
unfortunately, it doesn't work. I was wondering if there is a correct way to do this (scrolling down focused on the active div or any page element)?
Image below is provided to show the html structure of the said page.
Appreciate your help on this, thank you very much!
Can you try something like this?. This will scroll to the div element that you have mentioned.
Python Code
element = driver.find_element_by_xpath("xpath_of_div_element")
driver.execute_script("arguments[0].scrollIntoView(true);", element);
Java sample:
WebElement element = driver.findElement(By.id("id_of_div_element"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
Use this
liElement = driver.find_element_by_xpath("//div[#role='dialog']//ul//li[text()='required_li_element_visible_text']")
driver.execute_script("arguments[0].scrollIntoView(true);", liElement);

How to select input box on google webpage for simple selenium test?

I have created the following simple selenium test in order to start a browser, navigate to the google main page and to insert some text in the search box:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
browser = webdriver.Firefox()
browser.get('http://www.google.com')
elem = browser.find_element_by_xpath('//input') # Find the search box
elem.send_keys('do a test search' + Keys.RETURN)
However, I get the following error in the send_keys line:
selenium.common.exceptions.ElementNotInteractableException: Message: Element is not visible
Maybe this is a bad way to select the prominent input box on the google page? How to do it better?
(Remark: This is just supposed to be a simple setup to get selenium going. The system under test will be a different webpage, but I just want to make sure it works in this simple case...)
There are couple of hidden input elements located before search input field.
browser.find_element_by_xpath('//input') means return FIRST "input" node in DOM. That's why your elem is actually hidden node and not interactable.
Try below instead
elem = browser.find_element_by_name("q")

Categories

Resources