Python 3.x 如何使用selenium python3在一个网页上单击第二个按钮?

Python 3.x 如何使用selenium python3在一个网页上单击第二个按钮?,python-3.x,selenium,selenium-webdriver,web-crawler,Python 3.x,Selenium,Selenium Webdriver,Web Crawler,在python、selenium、Win 7中工作时,我想单击SOWComent按钮,在它能够单击位于该按钮上的可单击按钮后,由wait处理,然后我想单击showmore Comments按钮查看更多注释,以便刮取更多注释。在第一个按钮之后,我能够提取评论 from selenium import webdriver from selenium.common.exceptions import NoSuchElementException import selenium.common.excep

在python、selenium、Win 7中工作时,我想单击
SOWComent
按钮,在它能够单击位于该按钮上的可单击按钮后,由
wait
处理,然后我想单击
showmore Comments
按钮查看更多注释,以便刮取更多注释。在第一个按钮之后,我能够提取评论

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
import selenium.common.exceptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC  
import selenium.webdriver.support.ui as UI

driver = webdriver.Firefox()
driver.get("http://www.aljazeera.com/news/2016/07/erdogan-west-mind-business-160729205425215.html")
wait = UI.WebDriverWait(driver, 10)
next_page_link = wait.until(
                EC.element_to_be_clickable((By.ID, 'showcomment')))
next_page_link.click()

wait = UI.WebDriverWait(driver, 20)
next_page_link2 = wait.until(
                EC.element_to_be_clickable((By.LINK_TEXT, 'Show more comments')))
next_page_link2.click()

v = driver.find_elements_by_class_name('gig-comment-body')
print(v)
for h in v:
    print(h.text)
但第二个按钮无法单击,而是出现了异常:

selenium.common.Exception.TimeoutException:


问题是什么?

我认为您应该尝试使用
execute\u script()
执行以下单击操作:

next_page_link2 = wait.until(
        EC.element_to_be_clickable((By.XPATH, '//div[contains(text(),"Show more comments")]')))

#now click this using execute_script
driver.execute_script("arguments[0].click()", next_page_link2)

希望对您有所帮助……:)

您能在此处共享此链接的HTML吗??或者你试过其他定位器吗??或者尝试使用.PARTIAL\u LINK\u TEXT。@SaurabhGaur对于HTML,我提供了上面的链接,您可以访问。我也尝试了其他选择器,但都没有成功。这次我无法通过给定的链接查看HTML,因为我不在电脑上,这就是为什么我告诉你在这里共享链接HTML的原因。@SaurabhGaur
http://www.aljazeera.com/news/2016/07/generals-resign-turkey-military-council-160728055057094.html
@Saurah Gaur。努普。@Ali有什么例外吗???@Saurah Gaur。同样的例外:
元素在点(546.9833374023438,23.850006103515625)处不可单击。
@Ali您正在使用
。单击()
就是这样,请尝试单击使用
执行脚本,正如我在第二行中提供的那样……是的!我正在使用
执行脚本