Python中文
首页
教程
问答
标签
搜索
登录
注册
单击下拉框以获取可用的选项列表
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>当我使用手动检查选中一个下拉框时,总是会提供一个值。 当我使用selenium来选择值时,有时会提供一些选项</p> <pre><code>select = Select(self.driver.find_element_by_xpath(xpath)) print(",".join( [o.text for o in select.options]) </code></pre> <p>选项有时是空的</p> <p>就像用户单击下拉框时可以填充选项一样。 我尝试了以下所有方法</p> <pre><code>wait = WebDriverWait (brower, 10) optionValue = xpath + "/option[.='Value']" wait.until(EC.presence_of_element_located((By.XPATH, optionValue))) ... select.select_by_visible_text("Value") ... select.select_by_index(1) </code></pre> <p>select没有打开菜单的click()方法。你知道吗</p> <p>你有什么建议?你知道吗</p> <p><strong>自我回答——深深的歉意</p> <p>实际上,下拉菜单是在一个弹出窗口中,由一个按钮触发。当弹出窗口触发得太早时,它就永远不会被填满。因此,我添加了一个触发弹出窗口的测试,检查下拉列表的内容,如果下拉列表不包含值,我退出,等待一段时间,然后再做一次</p> <pre><code>nbAttemps = 5 waitTime = 2 optionIsFound = False while nbAttemps > 0: nbAttemps = nbAttemps - 1 self.driver.find_element_by_xpath("//button[.='No distribution']").click() selectXpath="//div/div/bla bla bla" select = Select(self.driver.find_element_by_xpath(selectXpath)) options = [o.text for o in select.options] optionIsFound = "Value" in options logger.debug("Options in select are " + ",".join( options)) logger.debug("nbAttemps = %d" % nbAttemps ) logger.debug("optionIsFound= %s, Value not in %s" % (optionIsFound,options)) if not optionIsFound: # close the popup webdriver.ActionChains(self.driver).send_keys(Keys.ESCAPE).perform() time.sleep(waitTime) else: select.select_by_visible_text("Value") nbAttemps = 0 </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>您可以首先使用<code>click()</code>方法单击下拉框,然后从下拉框中选择值。你知道吗</p> <p>如果下拉列表显示悬停在下拉列表上的列表,那么可以使用Action类,然后使用<code>moveToElement(element)</code>悬停在下拉列表上,然后使用<code>click()</code>方法单击下拉列表中所需的值。你知道吗</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何提高Djang的410误差
2 回答
如何提高doc2vec模型中两个文档(句子)的余弦相似度?
1 回答
如何提高Docker的日志限制?|[输出已剪裁,达到日志限制100KiB/s]
6 回答
如何提高DQN的性能?
8 回答
如何提高EasyOCR的准确性/预测?
4 回答
如何提高Euler#39项目解决方案的效率?
1 回答
如何提高F1成绩进行分类
9 回答
如何提高FaceNet的准确性
5 回答
如何提高fft处理的精度?
7 回答
如何提高Fibonacci实现对大n的精度?
3 回答
如何提高Flask与psycopg2的连接时间
8 回答
如何提高FosterCauer变换的scipy.signal.invres()的数值稳定性?
9 回答
如何提高gae查询的性能?
8 回答
如何提高GANs用于时间序列预测/异常检测的结果
10 回答
如何提高gevent和tornado组合的性能?
6 回答
如何提高googleappengin请求日志的吞吐量
4 回答
如何提高googlevision文本识别的准确性
3 回答
如何提高groupby/apply效率
4 回答
如何提高Gunicorn中的请求率
6 回答
如何提高G中的文件编码转换
8 回答