Select option in list with Selenium + Python - python

I'm using Selenium with Python to use this website and want to change page by clicking on the button designed for that. However, and I don't know why, this button is disabled and becomes enabled only if you choose another number of items to be displayed on the page.
I managed to programmatically click on the list to display all the options but didn't manage to select an option.
I tried with the following lines:
driver.find_element_by_xpath("//*[#id='edit-limit']/option[2]").click()
driver.find_element_by_xpath("//select[#id='edit-limit']/option[2]").click()
driver.find_element_by_link_text('50').click()
Does someone know how to solve this issue?

I will give a method for selecting option by value from dropdown list or select:
def set_select_element(self, element, val):
element = ui.Select(element)
return element.select_by_visible_text(val)
where element -- this is your select element on the page.

Related

Python with Selenium || how to select first option in listbox?

In a constantly updated listbox, I have to select the first tile each time.
This list will be constantly updated and I have to regularly click on the first option.
WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.CLASS_NAME,"dual-listbox__available"))).click()
I can't get a response from your code.
In the above code, you can get the first element by a CssSelector. Find the google chrome extension SelectorsHub so you can get the CssSelector easily which will solve your problem.

Selecting a dynamic drop down item in Selenium

I have a dynamic drop down menu and I want to select one of the items within it.
I have tried using the Select method but I believe that it doesn't work because the drop down isn't a select item. So instead, I think the solution would be to first click the drop down and then search for the item I want to select.
The drop down looks like this:
The drop down after it's been clicked looks like this:
The HTML code:
I have tried getting my Python script to click the drop down so that it expands but I believe I must be using the wrong ID (s2_id_autogen10_search). Any help or any other solution ideas would be appreciated.
EDIT:
So I am now trying to get Selenium to click the listbox to expand the options. Given the HTML code below, I am trying:
driver.find_element_by_id("select2-results-10").click()
However, it is not working. I receive this error.
selenium.common.exceptions.ElementNotInteractableException: Message: element
not interactable

id of xpath is getting changed every time in selenium python 2.7 chrome

one more problem i hv,i asked similar question earlier and i tried that method but not able use that methon in this problem so pls help me. it's element
html code is - FiltersĀ 
So basically, question is that there is one button its kind of toggle button and i want click on that button to select device like Desktop, Tablet & Mobile all check boxes are already (default) selected now i have to uncheck or deselect device, to do this, first i have to click on that toggle button , when i click on toggle button its id (gwt-uid-598) 598 is getting changed every time or every refresh. Can you pls help me, what should or which method should i follow in this case.
i am using below python code.
Click on device Filters
elem = driver.find_element_by_xpath('//*[#id="gwt-uid-598"]/div/div/span')
elem.click()
Thanks in advance.
Good question.
Try to use another selector, for example: css class or use xpath method contains().
Example: //div[contains(text(), "checkbox")]
I can help you if you can provide source code of the page or needed element.

Select from dropdown using Selenium Python, front end app - react.js

I want to select an item from a drop down using selenium python. The project uses react.js. The dropdown html appears in a div.
code inspect for dropdown
As this is under div, not select, when i try to select specific value, i got an error message.
Error message:
selenium.common.exceptions.UnexpectedTagNameException: Message: Select
only works on elements, not on div
How can I solve this issue?
You cannot use Select class to operate dropdowns which are not implemented using select and option elements.
You have to handle this kind of dropdown "manually" - generally speaking - click it to open it up, locate the desired dropdown item/option and click it. E.g., judging by you concise HTML snippet, to open up the dropdown you can try:
# open up the dropdown
dropdown = driver.find_element_by_css_selector(".Select-control")
# or dropdown = driver.find_element_by_css_selector(".Select-control .Select-input")
dropdown.click()
# TODO: select option
Sometimes, simply focusing the dropdown and typing the desired item/option text would auto-select it - if this is the case, you can try:
from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver)
actions.move_to_element(dropdown).send_keys("Desired option text").perform()
And, if there are any animations or time delays (to, for example, retrieve the options from the server) you may need to add Explicit Waits to handle the possible timing issues.
These are all general tips, I am operating under assumptions and I have no way to check if anything above works for your use case.

Internet browser using PySide: find id/tag of a selected element

Consider that I make a browser(Webkit) using PySide. I browse a few pages and use a combination like Ctrl+Click to select an element in some page, like a heading. The program must print the id/xpath or other tag properties of the clicked element. How do I proceed?

Categories

Resources