โดย mindphp » 15/09/2017 11:47 am
natnicha001 เขียน:จากการใช้
โค้ด: เลือกทั้งหมด
driver.find_element_by_xpath("//input[@name=\"post\"]").click()
มี error ดังนี้
โค้ด: เลือกทั้งหมด
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 ยังโหลดหน้านั้นมายังไม่เสร็จ
ทางแก้ให้ลอง ทำดังนี้
ตอนคลิกลิงค์ก่อนมาคำสั่งนี้ ให้ใส่ตัวหน่วงเวลาเข้าไปก่อน
ศึกษาเพิ่มเติมการใช้งาน
driver.implicitly_wait(30)
หรือ
time.sleep(1)
และ is_element_present เพื่อช่วยลดข้อผิดพลาด ก่อนใช้คำสั่ง find_element_by_***
[quote="natnicha001"]จากการใช้
[code]driver.find_element_by_xpath("//input[@name=\"post\"]").click()[/code]
มี error ดังนี้
[code]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)[/code][/quote]
ตาม Error
มันบอกว่า ว่า element not visible แปลว่ายังมองไม่เห็น element นั้น
ปัญหาอาจเป็นเพราะ หน้าที่เราต้องการให้ selenium หา element ยังโหลดหน้านั้นมายังไม่เสร็จ
ทางแก้ให้ลอง ทำดังนี้
ตอนคลิกลิงค์ก่อนมาคำสั่งนี้ ให้ใส่ตัวหน่วงเวลาเข้าไปก่อน
ศึกษาเพิ่มเติมการใช้งาน
driver.implicitly_wait(30)
หรือ
time.sleep(1)
และ is_element_present เพื่อช่วยลดข้อผิดพลาด ก่อนใช้คำสั่ง find_element_by_xxx