Python Forum

Full Version: Click in the (…) icon in youtube with selenium PyChrome
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I'm trying to do a bot that sign in youtube, pick a random video and click in the (...) button, I have done the SIGN IN and the video pick but I couldn't be able to click the button (...) inside the video. I have tried by ID, class name, xpath and css locator. I'm using python selenium PyChrome for this, thanks for your answers :)
Using this on python:
link = "youtube.com"
from pyChrome import PyChrome
browser = PyChrome()
browser.open(link)
#here goes the code for the SIGN IN and the video pick up, let's imagine that we have already picked one video
locator = ""
element = browser.findElement(id,classname,xpath,css = locator) #have tried those attributes
browser.clickElement(element)

By clicking in the inspect option of the button (...):
<button is="paper-icon-button-light" id="button" class="dropdown-trigger style-scope ytd-menu-renderer" aria-label="More actions">
<yt-icon class="style-scope ytd-menu-renderer"><svg viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" focusable="false" class="style-scope yt-icon" style="pointer-events: none; display: block; width: 100%; height: 100%;"><g class="style-scope yt-icon">
<circle cx="5" cy="12" r="2" class="style-scope yt-icon"></circle><circle cx="12" cy="12" r="2" class="style-scope yt-icon"></circle><circle cx="19" cy="12" r="2" class="style-scope yt-icon"></circle>
</g></svg>

</yt-icon>
<paper-ripple class="style-scope paper-icon-button-light circle">


<div id="background" class="style-scope paper-ripple" style="opacity: 0;"></div>
<div id="waves" class="style-scope paper-ripple"></div>
</paper-ripple></button>

The error message it's always: Couldn't find element or Couldn't click element by id,classname,css or Xpath
Ive never used pychrome, but have you tried it with just selenium and the default Chrome? Might as well be worth a test to see if this PyChrome has some issues.

What is the actual xpath you are using...i get
//*[@id="button"]/yt-icon

9/10 times i cant find an element; i forgot to delay as the program tripped over itself. Try to add a delay after logging in, as well as picking a video
(Oct-17-2017, 07:18 PM)metulburr Wrote: [ -> ]Ive never used pychrome, but have you tried it with just selenium and the default Chrome? Might as well be worth a test to see if this PyChrome has some issues.

What is the actual xpath you are using...i get
//*[@id="button"]/yt-icon

9/10 times i cant find an element; i forgot to delay as the program tripped over itself. Try to add a delay after logging in, as well as picking a video

Hello metulburr, thanks for the reply and I have already used that xpath and it goes to the "upload a video" button, it seems that they have the same xpath at that point and it is taking it first. I'm wondering if there is a chance to use the arial-label attribute, I have been looking for it but I couldn't find anything about it.
Can try this xPath.
//button[@aria-label="More actions"]
(Oct-17-2017, 10:37 PM)snippsat Wrote: [ -> ]Can try this xPath.
//button[@aria-label="More actions"]

This was the answer, Thank you!!!
(Oct-17-2017, 10:37 PM)snippsat Wrote: [ -> ]Can try this xPath.
//button[@aria-label="More actions"]

How did you find that via inspection?
Have to do it another way when inspection copy fails.
<button is="paper-icon-button-light" id="button" class="dropdown-trigger style-scope ytd-menu-renderer" aria-label="More actions">
aria-label is an attribute that can be selected with @(Selects attributes).
So as example the CSS class attribute would be:
//button[@class="dropdown-trigger style-scope ytd-menu-renderer"]
But as several buttons that has same name of class and id,there is aria-label="More actions" attribute that is unique to only that button.