Selenium - Scroll and click - python

I would like to know if there is any way to scroll down and also click on buttons at the same time.
For example Instagram. When you click on account 'follow' there is a pop up with images, text, and buttons.
There is any way to scroll and mean time to do other stuff?
For example, scroll down and click on the 'Follow' button while it's scrolling down.
Now I'm just using this code driver.execute_script("""arguments[0].scrollTo(0, arguments[0].scrollHeight); return arguments[0].scrollHeight;""", element)
Which is good, BUT it first scrolls all the way down, and when it finishes then I can do whatever I want to. Which is not the solution I'm looking for.
Any tips guys?
I'm using Chrome driver

Related

Selenium Instagram Bot - Clicking the "Like" Button

I have written a program to go on the Instagram explore page, and like the first six photos.
Right now, I am using this rather convoluted method to find the "Like" button.
I would much rather have it formatted like I did the "click the login button" section.
So far, I have tried inspecting various elements, but I cannot pinpoint the correct one to make it uniquely select the "Like" button. Also, I could just need to use an attribute that I am unfamiliar with to uniquely select the like button.
I am super new to the python and also the selenium, so any help is appreciated.
#like
self.driver.find_element_by_xpath('//*[#id="react-root"]/section/main/div/div[1]/article/div[3]/section[1]/span[1]/button').click()
sleep(3)
#Click login button
self.driver.find_element_by_xpath('//button[#type = "submit"]').click()
sleep(3)
to click on like, that web element is in svg tag, so try the below locator :
//button[#type='button']//*[name()='svg' and #aria-label='Like' and #height='24']
something like :
sleep(3)
self.driver.find_element_by_xpath("//button[#type='button']//*[name()='svg' and #aria-label='Like' and #height='24']").click()
Also, I am not sure what do you mean by
#Click login button

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

Force click highlights button but doesn't click it? - Python selenium

I am attempting to click on a button.
element.click() was not consistently clicking, so I tried to force a click driver.execute_script("arguments[0].click();", element). However, my force click doesn't click the button, but only highlights the borders of the button.
I suspected that perhaps the button was a dynamic element. But I tried accounting for that in my xpath.element.click() isn't consistent enough to use, but force click doesn't seem to be doing the trick.
I couldn't find any information about why a force click might not work, besides a dynamic element. Any ideas what might be going on?
driver.get("https://bi.prozorro.org/sense/app/fba3f2f2-cf55-40a0-a79f-b74f5ce947c2/sheet/HbXjQep/state/analysis")
element=WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, "//th[#tid='st.header']//span[#title='Учасник']//following::th[#tid='st.header.search']")))
#element.click()
driver.execute_script("arguments[0].click();", element)

How to click on button in popup dialog that isn't in page source

I want to write a script to legitimately mine coins in Agar.io by clicking the "Free Coins" button once every hour. To do this, I'm using Selenium's Firefox webdriver in Python:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://agar.io")
browser.find_element_by_id("freeCoins").click()
browser.find_element_by_xpath("//canvas/button[1]").click()
browser.quit()
By viewing the HTML source of the Agar.io webpage, I was able to find the ID of the "Free Coins" button to click on it, but in order to harvest the coins I need to click on the first button in the popup dialog that comes up:
I can't find the source code for the popup dialog, so I don't know how to find the "20 Coins" button to click it using Selenium.
In addition, there is often a popup dialog on the webpage when it first loads advertising some sort of sale on game purchases. It has a close button which I would also need to click using Selenium, but again I can't find the source code for it so I don't know how to.
Is there a way that I can click on these buttons using Selenium without being able to see their IDs or classes in the webpage's source code?

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