select a dropdown box using Selenium python - 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()

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.

How can I use selenium in python to select an item in a dropdown when the options are non-interactable <div> boxes?

I am trying to make a program that runs through the infamous https://userinyerface.com/ using selenium. However, I am getting stuck on the second page where there is a dropdown menu requiring you to select a top level domain. The dropdown menu is entirely made of divs and css, meaning none of the options have unique IDs, and seemingly cannot be interacted with using .click():
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
This is the entire HTML for the dropdown:
HTML code
What can I actually do? I read about the Select class as well, but I assume it will have the same result, and the elements are not uniquely identifiable by ID so not sure it can be used either way.
try this
driver.find_element_by_class_name('dropdown__list_item selected')[option_you_want_to_click_index].click()
This will help. You can have array with all of the selections and just click the first one.
Mas = driver.find_elements_by_class_name("dropdown__list-item")
Mas[1].click()

Clicking on dynamically loaded menu with python phantomjs

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()

Python Selenium , Click a checkbox

I am trying to create an add to car bot which finds the item and selects the size and fills out the user billing and card information. I am currently stuck on the checkboxes of the site. I've tried to use the XPath of the checkbox and it gives me an error or it won't execute.
The website I am using is as below:
https://www.supremenewyork.com/checkout
Below is a picture of the checkout page with the checkbox
Here is the html elements used for the code
Below is my code that I used to get the program to find the checkbox element and use a .click() to select the box.
Checkboxes = browser.find_element_by_xpath('//*[#id="cart-cc"]/fieldset/p[2]/label/')
Terms = ActionChains(browser).move_to_element(Checkboxes).click()
Terms.perform()
use below code:
Webelement element = browser.find_element_by_xpath('//label[./div[#class="icheckbox_minimal"]/input[type="checkbox"]]/div/input');
element.click();

python selenium: element not visible in [weird] dropdown to be clicked

There are two dropdown element code: one is standard option-select and the other is made of div, ul, li elements.
And somehow both are used to select a dropdown element via javascript...
Problem is selenium is not able to click the element and throws not visible exception.....
See the dropdown box here: [Its below "Top 5" tab]
http://www.oddsbox.com/baseball/mlb/record/section.odd
Following solutions don't help either:
Python Selenium: Find object attributes using xpath
selecting element in python selenium
Selenium nested li div menu select() or click() python
how to select custom dropdown list element from selenium
It would be nice if you'd post your code, so we can see a bit clearer what's happening.
Also admitted, I did not check all of your links to see everything that doesn't work. However my guess is this:
If you get an ElementNotVisible exception, then you should probably make your element visible before selecting it.
In this case I'd forget about the selecting commands and all and just :
- click on the element to open and reveal the menu and then
- click on the desired element inside that list.
Looks something like :
driver.find_element_by_xpath(".//*[#id='ctmSelectBox4_wrap']/button").click()
driver.find_element_by_xpath(".//*[#id='ctmSelectBox4_wrap']/div/ol/li[6]/label/span").click()
I personally detest these ugly xpaths (especially for maintainability), and probably would change that somehow, but that's not the scope of this question.
Hope that helps!

Categories