1

I have been trying to solve this for an entire week now and this is my last shot at this (asking stackoverflow).

I use phantomjs with selenium to go to the login page of YouTube and fill in the credentials and log in.

I get to the login page and it manages to fill in the email, but no matter what I try, it won't click on the "next" button.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.action_chains import ActionChains
import time
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.ui import WebDriverWait

dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["-phantomjs.page.settings.userAgent-"] = (
    "-Mozilla-5.0 (Windows NT 6.3; WOW64) AppleWebKit-537.36 (KHTML, like Gecko) Chrome-34.0.1847.137 Safari-537.36-"
    )

driver = webdriver.PhantomJS(desired_capabilities=dcap)

driver.set_window_size(1920,1080)
driver.get("https://youtube.com")
driver.find_element_by_class_name("yt-uix-button-content").click()
print("Logging in...")
driver.find_element_by_id("identifierId").send_keys("email")
time.sleep(1)
driver.find_element_by_class_name("ZFr60d").click()

driver.save_screenshot('testing4.png')

Now I have tried all these without any luck.

driver.find_element_by_xpath("""//*[@id="identifierNext"]/content/span""").click()

driver.find_element_by_css_selector("#identifierNext>content>span").click()

webdriver.ActionChains(driver).move_to_element(element).click(element).perform()

driver.find_element_by_id("identifierNext").click()

I would also like to add that clicking on the element works perfectly fine with selenium without PhantomJS.

When clicking next, there is a sliding animation that takes about 1 second.

I would really appreciate it if anyone here could help me.

  • 1
    PhantomJS is not going to be maintained by its creator any longer (see https://groups.google.com/forum/#!topic/phantomjs/9aI5d-LDuNE).. Consider switching to headless Chrome. Apart from that, time.sleep() is not the correct function to wait for something to happen. Consider WebDriverWait. – ggradnig Jul 25 '17 at 16:24
  • Where do I find headless chrome? – Daniel Carlsson Jul 25 '17 at 16:25
  • It ships with the chrome executable in version 59 (current stable) for Linux and Mac and in version 60 (canary) for Windows. You need to use the --headless flag when starting the application (i.e. chrome --headless). This should help getting it set up: https://intoli.com/blog/running-selenium-with-headless-chrome/ – ggradnig Jul 25 '17 at 16:29
  • Have you tried waiting until the element exists? https://stackoverflow.com/questions/7781792/selenium-waitforelement – Connor Jul 25 '17 at 21:26
  • Possible duplicate of [Python | PhantomJS not clicking on element](https://stackoverflow.com/questions/45294017/python-phantomjs-not-clicking-on-element) – undetected Selenium Jul 26 '17 at 05:37

0 Answers0