[英]Acquiring drop down menu option value selecting through name
I am new to python and I'm trying to understand how to click on a dropdown menu where I select it through the name and not the value even though the name is shown multiple times throughout the code because each shirt has a different value where a jacket can have 14123
and a shirt has 14133
as the value.我是 python 新手,我试图了解如何单击下拉菜单,我通过名称而不是值来选择它,即使名称在整个代码中多次显示,因为每件衬衫都有不同的值,其中夹克可以有14123
,衬衫的值是14133
。
Here is My Code:这是我的代码:
browser = webdriver.Chrome()
Size=browser.find_element_by_xpath("//select[@name='X-Large']/option[@value='12218866729085']").click()
HTML Code EX for one shirt:一件衬衫的 HTML 代码 EX:
select id="product-select" name="id" class="">
option value="12218866630781">Small</option>
option value="12218866663549">Medium</option>
option value="12218866696317">Large</option>
option value="12218866729085">X-Large</option>
Gives this error:给出这个错误:
("//select[@name='X-Large']/option[@value ='12218866729085']").click() AttributeError: 'str' object has no attribute 'click' ("//select[@name='X-Large']/option[@value='12218866729085']").click() AttributeError: 'str' 对象没有属性 'click'
你可以使用这个 xpath - //select/option[text()='Medium']
Its a select dropdown so you need to use select command to choose values from dropdown.它是一个选择下拉列表,因此您需要使用 select 命令从下拉列表中选择值。 for example in java例如在java中
Select dropdown = new Select(driver.findElement(By.id("product-select")));
dropdown.selectByVisibleText("Medium"); //to select medium
instead of visible text we can use index or value, like我们可以使用索引或值代替可见文本,例如
dropdown.selectByIndex(1); //second option in dropdown as count starts from 0 in java
or或者
dropdown.selectByValue("12218866663549"); //using value attribute
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.