【发布时间】:2019-12-20 05:47:44
【问题描述】:
在没有无头方法的情况下使用此代码.. 网址链接:https://www.na-kd.com/en/sweaters?sortBy=popularity&count=108
try:
element = self.driver.find_element_by_xpath('//*[@id="container"]/div/div/div[3]/div/div[4]/div/div[1]/div[2]/div[1]/button')
self.driver.execute_script("arguments[0].click();", element)
except Exception as e:
print('Error in clicking BTN : '+str(e))
因为这个 btn 里面有 div-tag,所以它不能与 headless 和 virtual-display 一起使用。
我也试试等待:
try:
element=WebDriverWait(self.driver, 20).until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="container"]/div/div/div[3]/div/div[4]/div/div[1]/div[2]/div[1]/button')))
self.driver.execute_script("arguments[0].click();", element)
except Exception as e:
print('Error in clicking BTN : '+str(e))
chromedriver --version
ChromeDriver 78.0.3904.70
谷歌浏览器 78.0.3904.108
【问题讨论】:
-
我看不到任何按钮,你能把这个的html代码发给我们
-
<div class="qb qc qy qtl"><div class="qtm"><button class="qb6 qcf qb8 qcz qcy qd0 qcx qor qos qot qou qbh qbi qbj qcn qbk qbl qaq qat qaw qaz qco qbo qef qbm qtn qto qkm qtp qtq qtr qip qiq qir qis qts qc6 qh" type="button"><span class="qa8 qr qbk qd8 qgk qix qiy qiz qcd qce"><div class="qtt qtu qcq">Load more products</div></span></button></div><div class="qtv qtw qtx qty qan qex ql9 qtz qu0 qey qu1 qu2 qu3"></div><div class="qa6 qn9 qu4">108 of 1736 products</div></div> -
在页面最后的“加载更多产品”按钮...
-
始终将代码、数据和错误消息放在有问题的地方,而不是在评论中。它将更具可读性,更多人会看到它。
-
好吧,让我纠正这个..
标签: python selenium selenium-webdriver selenium-chromedriver headless