擅长:python、mysql、java
<p>您可以在发生异常后将searchCountCheck设置为0。在</p>
<pre><code>try:
browser.find_element_by_css_selector("a[class='nclk']")
searchCount = browser.find_elements_by_xpath("//a[@class='nclk']")
searchCountCheck = len(searchCount)
flag = 1
except NoSuchElementException:
searchCountCheck = 0
flag = 0
</code></pre>
<blockquote>
<p>find_element_by_css_selector(css_selector) Finds an element by css
selector.</p>
<p>Args: css_selector - CSS selector string, ex: ‘a.nav#home’ Returns:<br/>
WebElement - the element if it was found Raises:<br/>
NoSuchElementException - if the element wasn’t found Usage: element =
driver.find_element_by_css_selector(‘#foo’)</p>
</blockquote>