Selenium WebDriver - Python - Simulate mouse scroll to the left/right using Selenium - python

In the my test-app that's built in angular there is a table with no scrollbar containing 10-11 columns. In the default view, there would be 8 fields displayed. To view the rest of fields, the user has to either use the mouse scroll to the right to view the fields/ use keyword arrow buttons. I need to simulate this in selenium webdriver to scroll to the 11th column so that I can perform further validations. I tried to use scrollintoview function in javascript. However, since the element is not displayed without scroll, it does not work. Please note that the html table do not contain any veritical/ horizontal scrollbars.

You can give a try with this.
javaScript = "document.getElementById('any_visible_locator').scrollLeft += -250;"
driver.execute_script(javaScript)

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 handle pop up windows in Robot Framework?

I need to handle a pop up window on an eCommerce site using Robot Framework.
I'm unable to post screenshots of the actual site I am working on but It is similar situation to the following. I select the item I want to purchase
Then I click on the Buy it now Button and a mini window pops up as follows:
The problem I am having is that Robot is not picking up the mini pop up window. I tried using the select window keyword, Set Focus to Element keyword but no luck as the elements within the mini window are not being found.
I get the same issue with you today and below is the way that I did:
Using Inspect Element to know exactly which type of popup (ex: iframe,...)
Get exactly locator of this iframe
Using Select Frame keyword, then I can do everything with element on this popup
Below is my example:
Click Button id:btnAddNewProduct
Sleep 20s
Select Frame xpath://div[#id='ContentModel']//iframe
Log to console OK

Select from dropdown using Selenium Python, front end app - react.js

I want to select an item from a drop down using selenium python. The project uses react.js. The dropdown html appears in a div.
code inspect for dropdown
As this is under div, not select, when i try to select specific value, i got an error message.
Error message:
selenium.common.exceptions.UnexpectedTagNameException: Message: Select
only works on elements, not on div
How can I solve this issue?
You cannot use Select class to operate dropdowns which are not implemented using select and option elements.
You have to handle this kind of dropdown "manually" - generally speaking - click it to open it up, locate the desired dropdown item/option and click it. E.g., judging by you concise HTML snippet, to open up the dropdown you can try:
# open up the dropdown
dropdown = driver.find_element_by_css_selector(".Select-control")
# or dropdown = driver.find_element_by_css_selector(".Select-control .Select-input")
dropdown.click()
# TODO: select option
Sometimes, simply focusing the dropdown and typing the desired item/option text would auto-select it - if this is the case, you can try:
from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver)
actions.move_to_element(dropdown).send_keys("Desired option text").perform()
And, if there are any animations or time delays (to, for example, retrieve the options from the server) you may need to add Explicit Waits to handle the possible timing issues.
These are all general tips, I am operating under assumptions and I have no way to check if anything above works for your use case.

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.

Unable to highlight text after selenium webdriver click()

I am using python code such as below to click an element within an iframe on an angularjs page.
browser = webdriver.Ie()
browser.switch_to.frame('name')
browser.find_element_by_id('value').click()
After using click() I am unable to manually highlight text that appears on the page. Why might this happen? How can I restore the ability to highlight text with the mouse?
I have tried switching back to default content, but this makes no difference. Any ideas?
Other strange effects after using click(): Links and buttons don't work while using the mouse manually unless double-clicked. These would normally require single click. It is as if there is an invisible overlay blocking text selection or clicking links. Radio buttons and menus still work.
Edit: The site uses silverlight and I am wondering if this is related to the problem that results from using click().

Categories

Resources