how to scroll item inside webelement using python selenium - python

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

Related

How to get element name or id in bootstrap carousel next button for Selenium Automation?

I am trying to automate bootstrap carousel next button with Selenium.
The code is given as follows:
from selenium import webdriver
import time
driver = webdriver.Chrome(executable_path='d:/CRD/chromedriver_win32/chromedriver.exe')
driver.get('file:///D:/slider/bootst.html')
button1 = driver.find_element(By.CLASS_NAME, "a.carousel-control")
button1.click()
The way I am trying to get the ID using chrome inspect element option as shown below:
How can I get the next button pressed automatically using Selenium.
You can use other selectors like XPATH if you want, but I think you should use CSS SELECTOR for "a.right.carousel-control" not CLASS_NAME.
More explanation on stackoverflow
Have a great day !

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)

How can I scroll a web page using selenium webdriver in python, for twitch?

I want to scroll vertical using Selenium.
I have read all the existing answers but non of them is working for the link
https://www.twitch.tv/directory/all
Kindly guide what is it about this page that makes the code
driver.execute_script("window.scrollTo(0, 1080);")
to have no effect at all.
Here is the complete code:
from time import sleep
from selenium import webdriver
driver = webdriver.Chrome('/home/sohaib/Desktop/chromedriver')
driver.get('https://www.twitch.tv/directory/all')
sleep(10)
driver.execute_script("window.scrollTo(0, 1080);")
driver.quit()`
Try this for vertical scroll,
from selenium.webdriver.common.keys import Keys
# Selects the first preview card
card = driver.find_element_by_xpath('//a[#data-a-target="preview-card-title-link"]')
card.send_keys(Keys.END) # Add a while loop to do infinite scroll
If you wants to use vertical scroll, You can use window.scrollBy(0,200) too,
driver.execute_script("window.scrollBy(0, 1080)")
You may try with JavaScriptExecutor as well,
js.execute_Script("window.scrollBy(0,1080)")

Scrolling through list using selenium Python till end

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()

Test for a 'transitory' DIV with Python Selenium Webdriver

I am attempting to automate a web application using the InternetExplorer driver in Python Selenium Webdriver. The web app indicates that it is fetching results by displaying a 'transitory' DIV, which contains a spinning circle icon.
So, if I automate searching for an item in the web application, as soon as I fire a click on the search button, the DIV becomes visible, then disappears when the results have been returned.
I know the class of the DIV ('loading-indicator'), I'm wondering if there is a way through Python Selenium to test for the DIV becoming visible, then test for the DIV becoming invisible as a way of then firing follow-on activity?
You could easily do it with is_displayed method :
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('yourPage.html')
element = driver.find_element_by_class('loading-indicator') #this element is visible
if element.is_displayed():
print "Spinning and spinning and spinning"
else:
print "Nothing spinning here"

Categories

Resources