擅长:python、mysql、java
<p>你可以用</p>
<pre><code>from selenium import webdriver
browser = webdriver.Chrome(somepath) # You should know what this does.
browser.execute_script("document.getElementById('pN').selectedIndex = 0;document.getElementById('optionList').submit();return false")
</code></pre>
<p>这意味着您可以使用.execute_script来执行Javascript代码,太棒了,对吧?在</p>
<p>无效的<code>InvalidSelectorException</code>是在没有元素或经验的情况下引发的预期,可能存在iframe,您必须使用<code>.switch_to.frame</code>才能与之交互。
另外,我喜欢使用XPath(总是最可靠的),它需要一点时间来适应,但是通过一两个小时的练习,您就可以做到。在</p>
<p>JeffC有一个很好的观点,HTML的结构,JS总是可以改变的。
您可以使用<code>find_element_by_xpath(xpath).click()</code>,但也有更动态的方法来预测结构是否会发生变化,使用类似<code>find_element_by_name</code>或其他可用的方法</strong>:</p>
^{pr2}$