![](/img/trans.png)
[英]How do I click a button in a form using Selenium and Python 2.7?
[英]How do I click a button using Selenium in Python?
我正在嘗試使用Python和Selenium從Google Play網站頁面上抓取應用程序上的評論數據。 我在這里要做的是單擊“完整評論”按鈕以查看每個評論的全文。
但是我每次都會遇到這些錯誤:
ElementNotInteractableException: Message: element not interactable
要么
AttributeError: 'list' object has no attribute 'click'
要么
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".LkLjZd ScJHi OzU4dc "}
該按鈕的元素是這樣的:
<button class="LkLjZd ScJHi OzU4dc " jsaction="click:TiglPc" jsname="gxjVle">Full Review</button>
按鈕的xpath是這樣的:
//*[@id="fcxH9b"]/div[4]/c-wiz/div/div[2]/div/div[1]/div/div/div[1]/div[2]/div/div[26]/div/div[2]/div[2]/span[1]/div/button
這是我用於xpath的代碼:
full_review = driver.find_elements_by_xpath('//*[@id="fcxH9b"]/div[4]/c-wiz/div/div[2]/div/div[1]/div/div/div[1]/div[2]/div/div[26]/div/div[2]/div[2]/span[1]/div/button')
full_review.click()
我找不到通過類名,xpath或任何東西的按鈕。 誰能幫我解決這個問題? 另外,是否可以通過jsname查找元素? 如果您能提供幫助,我將不勝感激。
盡可能避免使用xpath,因為它是最脆弱的選擇器。
id> CSS> Xpath
對於您的按鈕,此CSS選擇器應該起作用:
button[jsname='gxjVle']
您可能需要指定孩子,因為孩子可能不是唯一的
您的XPath選擇器有些不穩定,您可以將其簡化為:
//button[text()='Full Review']
WebDriver.find_element_by_xpath
一個,請注意該element
,而不是elements
假設以上所有:
full_review = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Full Review']")))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.