Same button id in python selenium - python

I have face the problem on clicking button on Python Selenium with same id
I can Have two buttons in one page named 'Upload' and 'Generate Base Form' but the two buttons id is same.
I will select the Button named "Generate Base Form". The id of the Button is also same.
I will attach the image of inspector
Image of Id for button

Although it's good practice to find elements by Id, Name or CssClass, in some cases you'll end up depending on more specific properties, so that you can exclusively locate the element. The most common solution is using XPath.
In your case, something like
driver.find_element_by_xpath("//button[#id='uploadButton' and #value='Upload']").click()
Should work. Notice that if the other button also has the same value attribute, you'll need to discover what's unique about the element you're trying to locate, and use it with XPath.
Alternatively, you could also do
driver.find_element_by_xpath("(//button[#id='uploadButton'])[buttonNumber]").click()
Where buttonNumber is an index that goes from 1 to n, accordingly to the number of buttons you have with that same id.
This article can help you with locating elements.

Use xpath
//input[#id='eRetVO.fileExtend']/../input[2]

Related

how can i select value from react dropdown using selenium python?

I am doing website testing in selenium python. I am not able to select a value from the dropdown. Can anyone help me to do that?
This is my website source code.
when expanding dropdown it does not show value in the DOM so how can I select state Alaska?
As per the attachment, text box accepts input and filters dropdown list based on our input..To handle these cases:
You can use Actions class to handle this.
Actions(driver).click(element).sendKeys("Alaska").sendKeys(Keys.ENTER).perform();
Here, we are communicating with search box cum dropdown and entering "Alaska" in it. Once it entered, it filters the results and display only Alaska in the dropdown.
Later Keys.ENTER just performs ENTER operation which will select the first record in the dropdown list.
Use text to identify WebElement. First click on dropdown and write generic xpath like '//*[text()='Alaska']'. This solution may or may not work. But solution 1 is recommendable..

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

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.

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

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

Categories