I tried to scrolling down with selenium, But i use webdriver PhantomJS. I tried selenium for test javascript instagram. As you know, on instagram there have button "Load More", after click button "Load More", we don't have to click again becouse it will auto refresh and it will show more image.
I tried like this :
driver.find_element_by_xpath("//a[#class='_8ioip _glw1t']").click()
time.sleep(5)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(3.6)
Actually this code it's work, but not really work, i mean something weird happening at the "time.sleep". If i give 2, the result are few and if i give 3 the result are just pretty much, But if i give 5, the result same like i give 2.
The question is, How to make teh Scroll get all data
class of "Load more" button seems to have changed.
your code is correct, try with this xpath:
//a[#class='_8imhp _glz1g']
or try to locate the button by it's text content:
//*/div/a[text()[contains(.,'Load more')]]
and before click the button scroll down.. so your code should looks like:
driver.get('https://www.instagram.com/explore/tags/whatever/')
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.find_element_by_xpath("//*[text()[contains(.,'Load more')]]").click()
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
Related
Why doesn't driver.execute_script("window.scrollTo(0, document.body.scrollHeight)") work on this apple music playlist? That line of code works fine on every other website I visit.
I tried doing action.send_keys_to_element(driver.find_element(By.TAG_NAME, 'html'), Keys.END) to no avail.
How else could I scroll to the bottom of the page?
Try to use any interactable node like below:
driver.find_element(By.CLASS_NAME, 'play-button').send_keys(Keys.END)
I'm trying to get Selenium to scroll down on a page and then click on a button (the arrows on the bottom right under the "Add+") , but I keep getting a NoSuchElementException error. Here's what I've tried, but still nothing is working.
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
element = driver.find_element_by_xpath('/html/body/div[7]/div/div/main/section[6]/main/div/main/div[2]/section[1]/p/button')
element.click()
Any help is appreciated.
You are using
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
which is basically, to scroll to the bottom of the page.
Please use this :
driver.execute_script("arguments[0].scrollIntoView(true);", element)
element.click()
this will basically scroll into the element view and element will be available in Selenium view port.
I wanted to click a "see more" button on a Facebook page, but nothing seems to work.
The code is something like this:
from selenium import webdriver
browser = webdriver.Chrome(chrome_options=chrome_options)
browser.get(url)
browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
browser.find_element_by_id("reaction_profile_pager1").click()
print("Click Successfull")
time.sleep(2)
I have tried literally every way one can find the thing to click in selenium (id, class, link name, name, etc.) and there is always a different error. However, I may have messed up with Xpath.
This is how the page code looks like:
Here is the link to that
The only thing that I want to do is press all "see more" buttons until no more is left.
I hope that someone knows what to do. Thank you for replies.
browser.find_element_by_xpath("//*[#class=\"clearfix mtm uiMorePager stat_elem _52jv\"]").click()
I was coding a script written in Py and Selenium that slides some slide and clicks a button of each slide, but sometimes, when the button is clicked, a popup is displayed, and other times the script should go regularly.
Can anybody explain me how to handle the ‘exception’ and How can write correctly the Code?
I'm sure to use Try and Exception, but I don't know how to recognize the Popup, so every attempt I tried failed.
try:
element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, “x”)))
element.click() #Click Slider Button
element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, “y”)))
element.click() #Click arrow to go to next slide
exception that, if popup is displayed, do this code
except driver.find_element_by_class_name(“z”).is_displayed():
element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, “f”)))#click to close popup
element.click()
element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, “y”)))
element.click() #click arrow to go to next slide
Try using some popups blocker extensions. If you use a chrome based navigator than this extension works perfectly and will block all possible popups.
Download the extension with this service and follow this question if you don't know how to use extensions with selenium.
This is not exactly the solution you want but it works.
I try to click on plus by xpath. But this plus becomes visible after the mouse cursor on it and my code can't click on this.
driver.find_element_by_xpath('/html/body/div[3]/div/div[5]/div[3]/div[12]/div[2]/div[2]/div[1]/div/div/div/div/div[2]/div/div/div[3]').click()
Is there any way in selenium webdriver to click on invisible elements
Hi please do it like below (code sample)
https://selenium.googlecode.com/git/docs/api/py/webdriver/selenium.webdriver.common.action_chains.html
menu = driver.find_element_by_css_selector("")
hidden_submenu = driver.find_element_by_css_selector("")
ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform()
You can click via javascript:
driver.execute_script("arguments[0].click();", element)
Though, I would use "Action Chains" to perform the mouse over + click.