Multiple Scroll Bars in Python Selenium - python

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

Related

How to move an internal HTML scrollbar using Selenium?

I am using Selenium + Python to scrape this site. I am interested in getting the information out of the Power BI table, which I can currently do using Beautiful Soup. My problem is that only the cells that are currently in view are loaded on the page. The rest are loaded as the table is scrolled, which can only be done if the mouse is over the table (in other words, this driver.execute_script('arguments[0].scrollIntoView(true);', target) doesn't work) or if the scroll bar is dragged downward. The code I am currently using tries to find the scrollBar element, click-and-hold, and drag it down some number of pixels to load another set of cells.
scrollBar = driver.find_element_by_class_name("scroll-bar-part-bar")
webdriver.ActionChains(driver).move_to_element(scrollBar).click_and_hold(scrollBar).move_by_offset(0,30).release().perform()
It kinda seems like the "mouse" isn't in the correct place when it clicks and holds. Is there a more straight forward was of doing this? I have tried simulating a mouse wheel scroll from this answer, but I am not able to get that to work either.
use:
driver.execute_script("arguments.scrollBy(0,arguments[0].scrollHeight)",scrollBar)
This scrolls the element, you should do scroll on the scroll bar element

How to posiiton an element to the top of a screen/view in appium python web driver

I am trying to take a screenshot of an element with a certain id using appium python. I want the element to be on the top of the screen so that I can grab the maximum content of that element. Currently, it takes a screenshot even if the element is at the very bottom, because of which I dont get to see the content.
It's quite confusing about your question, but from what I understand, you need to scroll the page so that the element is on top of the screen?
If so, try executing this script to your element, the element should be at top of your page now.
elem = driver.find_element_by_name("q")
driver.execute_script("arguments[0].scrollIntoView();", elem)
You can also try move_to_element then move_by_offset of page height but I don't recommend this.
If you want to take screenshot of full content of element, why not try:
elem.screenshot("foo.png")
screenshot method

how to scroll down with selenium webdriver?

I would like to scrape a webpage where in the main page there are 2 scroll bar. I can scroll down main scroll. But how can i scroll left side? i will attach a screenshot, because it is hard to explain it with words.
you can see that there 2 scroll in the picture. i would scroll left side with using selenium webdriver. How can i do this?
You can execute JavaScript code that's scrolling the page to specific X, Y and change the X (the Y is height).
Execute it like that:
driver.execute_script('window.scrollTo(X, Y)')
Just replace the X and Y for your scrolling values.
Example:
driver.execute_script('window.scrollTo(200, 0)') # It'll scroll to 200 left-position and also scrolling to 0 top-position.
You can use this JsExecutor script to scroll to the needed element:
driver.execute_script.execute_script("arguments[0].scrollIntoView(true);", element);

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

Is there a way to make selenium webdriver screenshot an entire page?

The title is pretty self explanatory. I have a page with an iframe and two columns (left and right)
Left has no scroll bar, while right has a scroll bar with a total of 600px to scroll. I need to screenshot the entirety of the right hand column. It doesn't matter if I get the entire page or not, as long as everything in the right hand column is in the screenshot.
I am using Selenium 2 Webdriver + python
There is workaround by following the steps described in http://www.ramandv.com/blog/angularjs-protractor-selenium-headless-end-end-testing/ and create a gaint virtual display for running your program.

Categories

Resources