Selenium Python - selecting from a list on the web with no stored/embedded options

2024/10/14 12:20:37

I'm very new to Python so forgive me if this isn't completely comprehensible. I'm trying to select from a combobox in a webpage. All the examples I've seen online are choosing from a list where the options are embedded within the code. I believe my issue is that the list I'm dealing with does not. The list is dynamic and the values are stored in a table.

So using the Select class method I keep getting the "Select only works on select elements, not on input" when using a command like this

Select(driver.find_element_by_xpath("//*[@id='sppProcessForm']/div[1]/form/table/tbody/tr/td[1]/span/input")).select_by_value('Q2-2018 Q2 GUIDANCE')

I get the unable to locate an element error when trying to use the Option method.

Here is the source code for the combobox along with the dropdown button. As you can see, no list options. I also just started learning about HTML so not sure how all that works.

<span class="custom-combobox"><input title="" class="custom-combobox-input ui-widget ui-widget-content ui-corner-left ui-autocomplete-input" autocomplete="off">
<a tabindex="-1" class="ui-button ui-widget ui-button-icon-only custom-anchor custom-combobox-toggle ui-corner-right" role="button">
<span class="ui-button-icon ui-icon ui-icon-triangle-1-s"></span><span class="ui-button-icon-space"> </span></a></span><span class="ui-button-icon-space"> </span>
Answer

Yes It is Possible to build drop down without using Select and Options tag which is available in HTML.

pseudocode :

elements = driver.find_elements_by_xpath("your xpath for drop down")

loop to iterate over this list

Inside loop if condition for a webelement like : webElement.getText().equals(" your value from drop down")

click on the element like element.click()

closure of if followed by closer of loop.

https://en.xdnf.cn/q/117959.html

Related Q&A

How to use a method in a class from another class that inherits from yet another class python

I have 3 classes :class Scene(object):def enter(self):passclass CentralCorridor(Scene):def enter(self):passclass Map(object):def __init__(self, start_game): passAnd the class map is initiated like this…

Finding common IDs (intersection) in two dictionaries

I wrote a piece of code that is supposed to find common intersecting IDs in line[1] in two different files. On my small sample files it works OK, but on my bigger files does not. I cannot figure out wh…

Run command line containing multiple strings from python script

Hello i am trying to autogenerate a PDF, i have made a python script that generates the wanted PDF but to generate it i have to call my_cover.py -s "Atsumi" -t "GE1.5s" -co "Ja…

Identify value across multiple columns in a dataframe that contain string from a list in python

I have a dataframe with multiple columns containing phrases. What I would like to do is identify the column (per row observation) that contains a string that exists within a pre-made list of words. Wi…

ipython like interpreter for ruby

I come from python background and am learning ruby. IPython is really awesome. I am new to ruby now, and wanted to have some sort of ipython things. As of now am having tough time, going along ruby lin…

Django dynamic verification form

Im trying to create a verification form in Django that presents a user with a list of choices, only one of which is valid.For example, for a user whose favourite pizza toppings includes pineapple and r…

Any method to denote object assignment?

Ive been studying magic methods in Python, and have been wondering if theres a way to outline the specific action of:a = MyClass(*params).method()versus:MyClass(*params).method()In the sense that, perh…

Delete lines found in file with many lines

I have an Excel file (.xls) with many lines (1008), and Im looking for lines that have anything with 2010. For example, there is a line that contains 01/06/2010, so this line would be deleted, leaving …

Combining semaphore and time limiting in python-trio with asks http request

Im trying to use Python in an async manner in order to speed up my requests to a server. The server has a slow response time (often several seconds, but also sometimes faster than a second), but works …

Import of SWIG python module fails with apache

Importing a python mdule throws an exception in django when I run with apache. The same source code works fine with the django development server. I can also import the module from the command line. Th…