[英]Selenium Wrapper to randomly select an element from a dropDown ( the location (xpath, css, ...) of the dropdown is provided)?
我想制作硒包装器以随机选择测试参数,例如可以从下拉列表中选择随机值......
Create list for all possible values from drop down for example you have drop down for country so your list will look like从下拉列表中为所有可能的值创建列表,例如您有国家/地区的下拉列表,因此您的列表看起来像
country = ['Australia', 'INDIA', 'CANADA', 'etc']
Make list using Visible text from DOM.使用来自 DOM 的可见文本制作列表。 Use choice function to select randomly
使用选择功能随机选择
.select_by_visible_text(random.choice(country ))
Another option is using index另一种选择是使用索引
country = Select(driver.find_elements(By.XPATH, '//xpath'))
country .select_by_index(randint(0, len(country .options) - 1))
Hope this helps希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.