{"id":762,"date":"2023-02-26T16:11:51","date_gmt":"2023-02-26T08:11:51","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=762"},"modified":"2023-04-29T16:59:37","modified_gmt":"2023-04-29T08:59:37","slug":"python-selenium-dropdown-box-select","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/26\/python-selenium-dropdown-box-select\/","title":{"rendered":"Python Selenium\u4e0b\u62c9\u6846\u9009\u62e9"},"content":{"rendered":"<p>\u6709\u65f6\u6211\u4eec\u4f1a\u78b0\u5230\u4e0b\u62c9\u6846\uff0cWebDriver\u63d0\u4f9b\u4e86<code>Select<\/code>\u7c7b\u6765\u5904\u7406\u4e0b\u62c9\u6846\u3002\u5982\u767e\u5ea6\u641c\u7d22\u8bbe\u7f6e\u7684\u4e0b\u62c9\u6846\uff0c\u5982\u4e0b\u56fe\uff1a<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-python\">from selenium import webdriver\nfrom selenium.webdriver.support.select import Select\nfrom time import sleep\n\ndriver = webdriver.Chrome()\ndriver.implicitly_wait(10)\ndriver.get(&#039;http:\/\/www.baidu.com&#039;)\n\n# \u9f20\u6807\u60ac\u505c\u81f3\u201c\u8bbe\u7f6e\u201d\u94fe\u63a5\ndriver.find_element_by_link_text(&#039;\u8bbe\u7f6e&#039;).click()\nsleep(1)\n# \u6253\u5f00\u641c\u7d22\u8bbe\u7f6e\ndriver.find_element_by_link_text(&#039;\u641c\u7d22\u8bbe\u7f6e&#039;).click()\nsleep(2)\n\n# \u641c\u7d22\u7ed3\u679c\u663e\u793a\u6761\u6570\nsel = driver.find_element_by_xpath(&quot;\/\/select[@id=&#039;nr&#039;]&quot;)\nSelect(sel).select_by_value(&#039;50&#039;)  # \u663e\u793a50\u6761\nsleep(5)\n# \u2026\u2026\n\ndriver.quit()<\/code><\/pre>\n<p><code>Select<\/code>\u7c7b\u7528\u4e8e\u5b9a\u4f4d<code>select<\/code>\u6807\u7b7e\u3002<code>select_by_value()<\/code>\u65b9\u6cd5\u7528\u4e8e\u5b9a\u4f4d\u4e0b\u63a5\u9009\u9879\u4e2d\u7684value\u503c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u65f6\u6211\u4eec\u4f1a\u78b0\u5230\u4e0b\u62c9\u6846\uff0cWebDriver\u63d0\u4f9b\u4e86Select\u7c7b\u6765\u5904\u7406\u4e0b\u62c9\u6846\u3002\u5982\u767e\u5ea6\u641c\u7d22\u8bbe\u7f6e\u7684\u4e0b\u62c9\u6846\uff0c\u5982\u4e0b\u56fe\uff1a f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[221],"tags":[],"class_list":["post-762","post","type-post","status-publish","format-standard","hentry","category-selenium"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/762","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=762"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/762\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=762"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=762"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}