Selenium - Python - Select dropdown meun option - No ID or Name

2024/10/12 14:18:41

I am trying to select and element in a dropdown menu:

The HTML is:

<div class="col-lg-6"><select data-bind="options: indicator_type_list,value: indicatorType,optionsCaption: 'Choose...', disable: $root.mode().isReadOnly()"><option value="">Choose...</option><option value="Malicious E-mail">Malicious E-mail</option><option value="IP Watchlist">IP Watchlist</option><option value="File Hash Watchlist">File Hash Watchlist</option><option value="Domain Watchlist">Domain Watchlist</option><option value="URL Watchlist">URL Watchlist</option><option value="Malware Artifacts">Malware Artifacts</option><option value="C2">C2</option><option value="Anonymization">Anonymization</option><option value="Exfiltration">Exfiltration</option><option value="Host Characteristics">Host Characteristics</option><option value="Compromised PKI Certificate">Compromised PKI Certificate</option><option value="Login Name">Login Name</option><option value="IMEI Watchlist">IMEI Watchlist</option><option value="IMSI Watchlist">IMSI Watchlist</option></select>
</div>

I have tried:

Select = Select(browser.find_element_by_xpath("//div[contains(.,'Choose...Malicious E-mailIP WatchlistFile Hash WatchlistDomain WatchlistURL WatchlistMalware ArtifactsC2AnonymizationExfiltrationHost CharacteristicsCompromised PKI CertificateLogin NameIMEI WatchlistIMSI Watchlist')]"))

and

test = browser.find_element_by_xpath("//option[@value='Malicious E-mail']") 
dropdown = test.find_element_by_xpath('..')
select = Select(browser.dropdown)

However I cannot seem to find the element to select the items in the dropdown.

Any help is appreciated!

Answer

There are multiple ways to locate this select element.

Here is one way - locate the select element that has a specific option inside:

from selenium.webdriver.support.select import Selectoption_value = "Malicious E-mail"select_element = browser.find_element_by_xpath("//select[option[@value = '%s']]" % option_value)
select = Select(select_element)
select.select_by_value(option_value)
https://en.xdnf.cn/q/118189.html

Related Q&A

How to prevent triples from getting mixed up while uploading to Dydra programmatically?

I am trying to upload some data to Dydra from a Sesame triplestore I have on my computer. While the download from Sesame works fine, the triples get mixed up (the s-p-o relationships change as the obje…

Adding a new row to a dataframe in pandas for every iteration

Adding a new row to a dataframe with correct mapping in pandasSomething similar to the above question.carrier_plan_identifier ... hios_issuer_identifier 1 AU…

Twisted client protocol - attaching an interface frontend

I am following the tutorial on writing a client/server pair in Twisted located here:http://twistedmatrix.com/documents/current/core/howto/clients.htmlI have everything working for the communication of …

Get query string as function parameters on flask

Is there a way to get query string as function parameters on flask? For example, the request will be like this.http://localhost:5000/user?age=15&gender=MaleAnd hope the code similar to this.@app.…

cython.parallel cannot see the difference in speed

I tried to use cython.parallel prange. I can only see two cores 50% being used. How can I make use of all the cores. i.e. send the loops to the cores simultaneously sharing the arrays, volume and mc_vo…

Is it possible (how) to add a spot color to pdf from matplotlib?

I am creating a chart which has to use (multiple) spot colors. This color could be one that is neither accessible from RGB nor CMYK. Is there a possibility to specify a spot color for a line in matplot…

Separate keywords and @ mentions from dataset

I have a huge set of data which has several columns and about 10k rows in more than 100 csv files, for now I am concerned about only one column with message format and from them I want to extract two p…

Kivy class in .py and .kv interaction 2

Follow up from Kivy class in .py and .kv interaction , but more complex. Here is the full code of what Im writing: The data/screens/learnkanji_want.kv has how I want the code to be, but I dont fully un…

How to centre an image in pygame? [duplicate]

This question already has an answer here:How to center an image in the middle of the window in pygame?(1 answer)Closed 1 year ago.I am using python 2.7, I would like to know if there is a way to centr…

widget in sub-window update with real-time data in tkinter python

Ive tried using the after/time.sleep to update the treeview, but it is not working with the mainloop. My questions are: How can I update the treeview widget with real-time data? And is there a way th…