1.原始需求,选择省份后,相应的城市会自动加载 2.思路 a.获取下拉框的所有元素个数 b.随机点击0-元素个数之间的某个值 3.代码实现 Random random = new Random(); Select slp = new Select(dr.findElement(By.id("province"))); int psize = slp.getOptions().size()-1; int p = random.nextInt(psize); slp.selectByInd
Js获取下拉框的值和文本网上提供了2种方法:但有些人很不负责任,他们根本没考虑到浏览器之间的差异导致的错误,导致很多新手琢磨了半天找不出错误! 下面我总结下Firefox和IE下获取下拉框选定项的值和文本: 1. IE和Firefox都支持的方法: 获取文本 var obj=document.getElementById('select_template'); var text=obj.options[obj.selectedIndex].text;//获取文本 var obj=document
js获取select选中的值: var sel=document.getElementById("select1"); var index = sel.selectedIndex; // 选中索引 albumid= sel.options[index].value;//要的值 jQuery获取下拉框选中的option: $("#s option:selected").val();
// 获取下拉框所选下标 传入下拉框的id function getselectscheckitemindex (idStr) { let o = document.getElementById(idStr).options for (let i = 0; i < o.length; i++) { if (o[i].selected == true) return i } }
示例脚本: click element id=provinceName #点击地区 省 wait until element is enabled xpath=.//*[@id='provinceNameDataGrid']/tbody/tr #等待 省份下拉框的出现 ${count1} get matching xpath count xpath=.//*[@id='provinceNameDataGrid']/tbody/tr #获取省份下拉值的数量 ${s1} evaluate rando
"""处理下拉框""" from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as ES from selenium.web