我试图点击此HTML的元素:
<div class="feed-item__explanation" style="padding-left: 15px;">
<a href="javascript:" ng-click="carinext()">Load more</a>
</div>
我使用硒来处理这个问题:
driver.get(url)
while True:
try:
driver.find_element_by_xpath('//a[text()="Load more"]')
print 'found'
except Exception as e:
print e
break
可以处理该代码并提供输出&#39;。 但是,当我试图点击该元素时,
driver.find_element_by_xpath('//a[text()="Load more"]').click()
我收到这样的错误:
消息:元素不可见 (会议信息:chrome = 62.0.3202.94)
这是处理AngularJS脚本的问题吗?
答案 0 :(得分:2)
您可能需要向下滚动到所需元素才能单击它。请尝试以下代码:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
load_more = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.LINK_TEXT, "Load more")))
driver.execute_script('arguments[0].scrollIntoView();', load_more)
load_more.click()