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..
Related
I'm new to using Selenium, and I am having trouble figuring out how to click through all iterations of a specific element. To clarify, I can't even get it to click through one as it's a dropdown but is defined as an element.
I am trying to scrape fanduel; when clicking on a specific game you are presented with a bunch of main title bets and in order to get the information I need to click the dropdowns to get to that information. There is also another drop down that states, "See More" which is a similar problem, but assuming this gets fixed I'm assuming I will be able to figure that out.
So far, I have tried to use:
find_element_by_class_name()
find_element_by_css_selector()
I have also used them in the sense of elements, and tried to loop through and click on each index of the list, but that did not work.
If there are any ideas, they would be much appreciated.
FYI: I am using beautiful soup to scrape the website for the information, I figured Selenium would be helpful making the information that isn't currently accessible, accessible.
This image shows the dropdowns that I am trying to access, in this case the dropdown 'Win Margin'. The HTML code is shown to the left of it.
This also shows that there are multiple dropdowns, varying in amount based off the game.
You can also try using action chains from selenium
menu = driver.find_element_by_css_selector(".nav")
hidden_submenu = driver.find_element_by_css_selector(".nav # submenu1")
ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform()
Source: here
am new to coding and have been trying to select a dropdown box to select underlying options. Have been able to interact with other drop-down on this page, though this particular one seems different as I've been unable to access/interact with it
I've included a snapshot of the webpage's drop-down box, source codes for the specific drop-down box, and codes that I've already tried and had errors with.
Would appreciate any help/pointers. Am a complete newb to coding (python or HTML!), but know a little about Excel VBA.
website: https://www.firstsentierinvestors.com/sg/en/retail/performance/price-and-performance.html
Tried to paste a picture though it seems I'm too new to do so directly. I'm trying to interact with the "Select Fund" drop-down box on the page. Have tried the following codes:
browser.find_element_by_id('strategy').send_keys(fund_strat) #works fine
browser.find_element_by_xpath('//*[#id="share-class"]').click()
#this line directly above does not work, including variants below:
browser.find_element_by_xpath('THE BELOW XPATHS').click()
//*[#id="price-performance-form"]/div[3]
//*[#id="price-performance-form"]/div[3]/div
//*[#id="price-performance-form"]/div[3]/div/a
//*[#id="price-performance-form"]/div[3]/div/a/span
//*[#id="share-class"]
//*[#id="share-class"]/option[1]
Also tried using CSS selector
browser.find_element_by_css_selector('a.option-selected').click()
browser.find_element_by_css_selector('a.option-selected').send_keys('NAME OF FUNDS ETC')
Image describing problem
If the below line works fine for you then,
browser.find_element_by_xpath('//*[#id="share-class"]').click()
#this line directly above does not work, including variants below:
You need to wait for the element which is visible on the DOM.
i.e.,css = <div class="custom-select custom-select-open">
These days most of the web apps are using AJAX techniques.
So you need to add a wait duration (till the element gets visible on the page or get loaded on the DOM).
So, Try using Selenium Waits(put below code):
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.XX, 'element')))
XX = CSS, XPATH, ID, etc.
Now, If you want to write on the selected text box then just try to send keys on input element.
browser.find_element_by_css_selector('.editable-select input')
for much better selector use parent elements to locate the exact element.
CSS = 'div[class$="custom-select custom-select-open"] .editable-select input'
If you want to select dropdown options and you know the Values. Try using below CSS.
browser.find_element_by_css_selector('select option[value$="Your Value"]')
or
If you don't know the values then please attach whole DOM feed after typing into the text box. I'll try to help you out with the Dropdown selection of item.
Else, there is few more steps are there that you need to workout. Get all elements using inside text.
Note: You can approach the text search of an element using XPATH. Example : xpath = "//*[contains(text(),'your text')]"
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()
I am trying to mimic selecting a value from an ajax dropdown value using selenium and python. I am not sure how to approach this.
This is how the text box works - I enter in the value, it searches for it and appears at the bottom of the text box as an ajax drop down. How can I select that using selenium and python?
Here is the highlighted html code for that field
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]