Traceback (most recent call last):
File "/home/com010/m050/test2.py", line 37, in <module>
driver.find_element_by_xpath("//input[@name=\"post\"]").click()
File "/home/com010/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 77, in click
self._execute(Command.CLICK_ELEMENT)
File "/home/com010/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 493, in _execute
return self._parent.execute(command, params)
File "/home/com010/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 256, in execute
self.error_handler.check_response(response)
File "/home/com010/.local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
(Session info: chrome=61.0.3163.79)
(Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 4.10.0-33-generic x86_64)
ตาม Error
มันบอกว่า ว่า element not visible แปลว่ายังมองไม่เห็น element นั้น
ปัญหาอาจเป็นเพราะ หน้าที่เราต้องการให้ selenium หา element ยังโหลดหน้านั้นมายังไม่เสร็จ
ทางแก้ให้ลอง ทำดังนี้
ตอนคลิกลิงค์ก่อนมาคำสั่งนี้ ให้ใส่ตัวหน่วงเวลาเข้าไปก่อน
Traceback (most recent call last):
File "/home/com010/m050/test2.py", line 39, in <module>
driver.assertTrue(driver.is_element_present(By.NAME, "post"))
AttributeError: 'WebDriver' object has no attribute 'assertTrue'
Traceback (most recent call last):
File "/home/com010/m050/test2.py", line 39, in <module>
driver.is_element_present(By.NAME, "post")
AttributeError: 'WebDriver' object has no attribute 'is_element_present'
Traceback (most recent call last):
File "/home/com010/m050/test2.py", line 43, in <module>
driver.is_element_present(By.NAME, "post")
AttributeError: 'WebDriver' object has no attribute 'is_element_present'
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
browser = webdriver.Chrome('D:\\tmp\\chromedriver.exe')
browser.get('https://www.mindphp.com/forums/ucp.php?mode=login')
user = browser.find_element_by_css_selector('#username')
user.send_keys('ชื่อ User')
password = browser.find_element_by_css_selector('#password')
password.send_keys('รหัสผ่าน')
login = browser.find_element_by_name('login')
login.click()
# กดปุ่ม like ใน post ที่ต้องการ
browser.get('https://www.mindphp.com/forums/viewtopic.php?f=16&t=42465&start=8')
wait = WebDriverWait(browser, 5)
wait.until(EC.visibility_of_element_located((By.ID, "like_img_104452")))
browser.find_element_by_id("like_img_104452").click()