Clicking on dynamically loaded menu with python phantomjs - python

I want to get the transcript from the youtube video below (I know that there is a way to get the cc captions if available, but often they are not).
I use phantomjs to do this in python.
url = 'https://www.youtube.com/watch?v=wOn8xawC-HQ'
phantom_driver = webdriver.PhantomJS(executable_path="./phantomjs-2.1.1- macosx/bin/phantomjs")
phantom_driver.get(url)
The transcript only appears after clicking on the "More ..." button which I can access with:
phantom_driver.find_element_by_id('action-panel-overflow-button').click()
... this creates a div with the compound class "yt-uix-menu-content yt-ui-menu-content yt-uix-kbd-nav yt-uix-menu-content-hidden" which contains a menu with a <ul> consisting of 4 elements in it.
I need to click on one of these four elements to open the transcript box (specifically, I need to click the button with the compound class "yt-ui-menu-item has-icon yt-uix-menu-close-on-select action-panel-trigger action-panel-trigger-transcript").
However, running
phantom_driver.find_element_by_class_name('action-panel-trigger-transcript').click()
does not work since the element seems still hidden (Element is not currently visible and may not be manipulated).
I believe what I need is clicking on the "More..." button and then directly clicking on the opened menu.
I've looked into this post on select menues and this one on using the html after the click. Neither did quite solve my problem.
What am I missing in my script? Do I need to "refresh" the retrieved html after the click?

"action-panel-overflow-button" is button id not name.
you can click this element by it's xpath
this works fine:
phantom_driver.find_element_by_xpath('//*[#id="action-panel-overflow-button"]').click()
phantom_driver.find_element_by_xpath('//*[#class="yt-ui-menu-item has-icon yt-uix-menu-close-on-select action-panel-trigger action-panel-trigger-transcript"]').click()

Related

RobotFramework - Unable to click element using selenium library but Execute Javascript click works

I am using RobotFramework to automate one application. I am using the selenium library. For the whole application, selenium keywords "Click Button" and "Click Element" throw an error stating "ElementClickInterceptedException: Message: element click intercepted: Element **** is not clickable at point (376, 289). Other element would receive the click: ..."
I am able to identify the element using ID and it is not under any iframe or shadow-root element. but still I am not able to click on the element. I also tried with adding wait commands to see if it is sync issue but it is not. I tried to click using Action class, mouse move and click etc but did not work.
I tried to take the screenshot of the element using "Capture Element Screenshot" and it captures the screenshot of an empty place however, when I try to locate element in the browser dev tool, it locate it exactly
Only working solution I found is to run "Execute Javascript" keyword to click on the element such as
Execute Javascript $('#id').click();
Question:
Though I am able to make it work, I am curious to know what could be the issue in the application. I am not able to share the application dom code due to restriction. Sorry for that
This means that the element you trying to click is
Out of the visible screen (view port) so you need to scroll the page to make that element accessible or
It is covered by some other element - for example you should open a drop down menu etc or
You trying to click the element while it is still not fully rendered - in this case you need to add some delay to make the element fully rendered and be ready to accept clicks.
Selenium generally imitates human GUI actions. So, as a human user you can't click element inside drop-down without opening it. And you can't click element out of the visible screen. This is why Selenium .click() methods can't click such elements.
JavaScript click is more powerful tool, it can click invisible, covered etc. elements. It doesn't imitate human GUI actions.

Can't find the button to click with selenium

Trying to click on the button on "https://euw.op.gg/summoner/userName=JengaSneaky". But I can't find the element that trigger it.
The pic shows one of the buttons. I want Selenium to click on it so I can scrape the data that pops up. I've tried to find the element but it says I can't use it with click().
The problem with these kind of buttons is that they are generated each time you load the html ( or the page ) based on the data contained in a database that changes everyday.
That's why they don't come with a unique id or something to distinguish them from others.
The thing you could do here is to find them by the CSS SELECTOR or by XPATH.
But you will always have to check if they changed everyday.
What you could also try to do is locate them if they contain a specific text.

How to Find an Element to Click on Instagram Unfollow Button

I am making an Instagram bot using selenium and python. I am trying to implement a function which allows a certain amount of followers to be unfollowed. The code navigates to the unfollow screen which has many buttons that say unfollow. The buttons are hard to find with selenium though. If the find_element_by_tag('button') function is used only 3 buttons are found. The button html is:
<button class="_0mzm- sqdOP L3NKy _8A5w5 " type="button">Following</button>
For some reason, I cannot get selenium to select the element. Are there any ways someone can see how to click it?
Try switching to the active element and then clicking on the following
driver. switchTo() . activeElement() ;
And then try the xpath that you tried. This should work
Copy the xpath of the button tag and create reference and use for loop to iterate from one unfollow button onto the next, see my github repository
https://github.com/asadamatic/Unfollow-All-On-Instagram/blob/master/unfollowAll.py

I have a button that im trying to click with selenium however there are more css selectors than buttons

I am trying to click on the 'details' button on https://www.rogers.com/web/totes/wireless/choose-phone. However it seems as though I cant click it. The page seems to be dynamic and so the link does not change.
I have tried selecting the button by link but only to realise it stays on the same link regardless if that button is click. There are 66 elements under the 'details' button when there should only be 32. Therefore when I try selecting any from that list of elements, none work.
phoneDetailsPath = wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, '.select-font.ng-scope')))
phoneDetailsPath[num].click()
I am hoping to be able to store all the 'details' paths into a list and click the button at that index.
In case it helps you can use selector
[ng-click*=gotoDeviceConfigure]
Automationists won't like using javascript but you can execute click as follows:
#first item
driver.execute_script('document.querySelector("[ng-click*=gotoDeviceConfigure]").click();')
# using indices
driver.execute_script('document.querySelectorAll("[ng-click*=gotoDeviceConfigure]")[1].click();')
However, you need to scroll later elements into view and you need to handle dimissing pop-ups about being signed up unless already logged in (I guess).

select a dropdown box using Selenium python

I am having trouble selecting a particular dropdown element via Selenium. The website is password protected so I have shared a snapshot of it. The attached snapshot shows what is visible when I right-click on the element and choose 'Inspect'. I am selecting XPATH which I have pasted in the pictures address bar to show what it is. Then I use the following line in my script to click it but it says element is not visible.
WebDriverWait(Chromedriver, 240).until(EC.presence_of_element_located((By.XPATH, '//*[#id="dateRangeType"]'))).click()
I have noticed that this element does not have a class to it. If that is the reason it is not working, how would I select an element with id, name but no class?
I found the answer myself, the element was supposed to be clicked from the top of its hierarchy:
WebDriverWait(Chromedriver, 240).until(EC.presence_of_element_located((By.XPATH,'//*[#id="individual_member_det"]/div/div/div[6]/select'))).click()

Categories