การเขียน selenium webdriver ด้วยภาษา python
Moderator: mindphp, ผู้ดูแลกระดาน
- mindphp
- ผู้ดูแลระบบ MindPHP
- โพสต์: 41251
- ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
- ติดต่อ:
Re: การเขียน selenium webdriver ด้วยภาษา python
การใช้งาน XPath ลองดูที่นี่
https://www.mindphp.com/forums/viewtopic ... 77&t=23622
https://www.mindphp.com/forums/viewtopic ... 77&t=23622
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
-
- PHP Hero Member
- โพสต์: 120
- ลงทะเบียนเมื่อ: 28/08/2017 10:14 am
Re: การเขียน selenium webdriver ด้วยภาษา python
จากการใช้ submit() ไม่ error แต่ไม่มีอะไรเกิดขึ้น
ส่วนการใช้ click()
มี error ดังนี้
โค้ด: เลือกทั้งหมด
driver.find_element_by_xpath('//*[@id="postform"]/div[2]/div/fieldset/input[4]').submit()
โค้ด: เลือกทั้งหมด
driver.find_element_by_xpath('//*[@id="postform"]/div[2]/div/fieldset/input[4]').click()
โค้ด: เลือกทั้งหมด
Traceback (most recent call last):
File "/home/com010/m050/test2.py", line 30, in <module>
driver.find_element_by_xpath('//*[@id="postform"]/div[2]/div/fieldset/input[4]').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.WebDriverException: Message: unknown error: Element is not clickable at point (614, 720)
(Session info: chrome=61.0.3163.79)
(Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 4.10.0-33-generic x86_64)
-
- PHP Hero Member
- โพสต์: 120
- ลงทะเบียนเมื่อ: 28/08/2017 10:14 am
Re: การเขียน selenium webdriver ด้วยภาษา python
จาก element
ต้องการ input[4]
โค้ด: เลือกทั้งหมด
<fieldset class="submit-buttons">
<input type="hidden" name="lastclick" value="1505388154">
<input type="submit" accesskey="k" tabindex="7" name="save" value="บันทึกข้อความร่าง" class="button2">
<input type="submit" tabindex="5" name="preview" value="แสดงตัวอย่างหัวข้อ" class="button1" onclick="document.getElementById('postform').action += '#preview';">
<input type="submit" accesskey="s" tabindex="6" name="post" value="โพสต์" class="button1 default-submit-action">
</fieldset>
-
- PHP Hero Member
- โพสต์: 120
- ลงทะเบียนเมื่อ: 28/08/2017 10:14 am
Re: การเขียน selenium webdriver ด้วยภาษา python
จาก selenium webdriver เขียนด้วย ภาษา python
โค้ด: เลือกทั้งหมด
# -*- coding: utf-8 -*-
from selenium import webdriver
driver = webdriver.Chrome('/usr/local/lib/python2.7/site-packages/chromedriver')
#เปิด ling mindphp
driver.get('https://www.mindphp.com/forums/index.php?sid=7e30176647e1b208585241f76022ae41')
#เปิด ling เข้าสู่ระบบ
driver.get('https://www.mindphp.com/forums/ucp.php?mode=login&sid=3b0d5a880c9645c9559b8bd015ae411f')
#พิมพ์ natnicha
user = driver.find_element_by_css_selector('#username')
user.send_keys('xxxxxxxx')
#พิมพ์ รหัส
password = driver.find_element_by_css_selector('#password')
password.send_keys('xxxxxxxx')
#คลิก login
login = driver.find_element_by_name('login')
login.click()
#เข้าเว็บ
driver.get('https://www.mindphp.com/forums/viewforum.php?f=6')
# คลิกเข้าปุ่มตอบกลับกระทู้
driver.find_element_by_xpath('//*[@id="page-body"]/div[2]/div[1]/a').click()
# พิมพ์ข้อความที่หัวกระทู้
title = driver.find_element_by_xpath('//*[@id="subject"]')
title.send_keys('title')
# พิมพ์ข้อความ test
Content = driver.find_element_by_xpath('//*[@id="message"]')
Content.send_keys('test1')
# คลิกปุ่มโพส
driver.find_element_by_xpath('//*[@id="postform"]/div[2]/div/fieldset/input[4]').click()
- mindphp
- ผู้ดูแลระบบ MindPHP
- โพสต์: 41251
- ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
- ติดต่อ:
Re: การเขียน selenium webdriver ด้วยภาษา python
Error ว่าอะไรerror บรรทัด สุดท้าย
หา ตำแหน่งไม่เจอ หรือ ใช้ .submit() ไม่ได้
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
-
- PHP Hero Member
- โพสต์: 120
- ลงทะเบียนเมื่อ: 28/08/2017 10:14 am
Re: การเขียน selenium webdriver ด้วยภาษา python
จากการใช้ .submit() ไม่เออเร่อ แต่ไม่สามารถโพสข้อความได้
จากการใช้.click() error ตามข้างล่าง
error ที่เกิดขึ้น
โค้ด: เลือกทั้งหมด
driver.find_element_by_xpath('//*[@id="postform"]/div[2]/div/fieldset/input[4]').submit()
โค้ด: เลือกทั้งหมด
driver.find_element_by_xpath('//*[@id="postform"]/div[2]/div/fieldset/input[4]').click()
โค้ด: เลือกทั้งหมด
Traceback (most recent call last):
File "/home/com010/m050/test2.py", line 30, in <module>
driver.find_element_by_xpath('//*[@id="postform"]/div[2]/div/fieldset/input[4]').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.WebDriverException: Message: unknown error: Element is not clickable at point (614, 720)
(Session info: chrome=61.0.3163.79)
(Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 4.10.0-33-generic x86_64)
- mindphp
- ผู้ดูแลระบบ MindPHP
- โพสต์: 41251
- ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
- ติดต่อ:
Re: การเขียน selenium webdriver ด้วยภาษา python
ลองดูตามโค้ดนี้
โค้ด: เลือกทั้งหมด
driver.find_element_by_xpath("//input[@name=\"post\"]").click()
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
-
- PHP Hero Member
- โพสต์: 120
- ลงทะเบียนเมื่อ: 28/08/2017 10:14 am
Re: การเขียน selenium webdriver ด้วยภาษา python
จากการใช้
มี error ดังนี้
โค้ด: เลือกทั้งหมด
driver.find_element_by_xpath("//input[@name=\"post\"]").click()
โค้ด: เลือกทั้งหมด
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)
- nuattawoot
- PHP VIP Members
- โพสต์: 2561
- ลงทะเบียนเมื่อ: 05/06/2017 9:34 am
Re: การเขียน selenium webdriver ด้วยภาษา python
ผมใช้โค้ดนี้ก้คลิกได้ ปกตินะ ลองใหม่ครับ
อันนีคลิกจาก link_text ไม่แนะนำ
ถ้าไม่ได้ให้ลองไปใช้ webdriver.Firefox ครับ
โค้ด: เลือกทั้งหมด
browser.find_element_by_name("post").click()
โค้ด: เลือกทั้งหมด
browser.find_element_by_link_text(u"โพสต์").click()
ถ้าไม่ได้ให้ลองไปใช้ webdriver.Firefox ครับ
First Bug Love you
-
- PHP Hero Member
- โพสต์: 120
- ลงทะเบียนเมื่อ: 28/08/2017 10:14 am
Re: การเขียน selenium webdriver ด้วยภาษา python
จากการใช้
error
จากการใช้
error
ไม่สามารถเปิดด้วย firefox
error
โค้ด: เลือกทั้งหมด
driver.find_element_by_name("post").click()
โค้ด: เลือกทั้งหมด
Traceback (most recent call last):
File "/home/com010/m050/test2.py", line 37, in <module>
driver.find_element_by_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)
จากการใช้
โค้ด: เลือกทั้งหมด
driver.find_element_by_link_text(u"โพสต์").click()
โค้ด: เลือกทั้งหมด
Traceback (most recent call last):
File "/home/com010/m050/test2.py", line 37, in <module>
driver.find_element_by_link_text(u"โพสต์").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.WebDriverException: Message: unknown error: Element is not clickable at point (973, 936)
(Session info: chrome=61.0.3163.79)
(Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 4.10.0-33-generic x86_64)
ไม่สามารถเปิดด้วย firefox
error
โค้ด: เลือกทั้งหมด
Traceback (most recent call last):
File "/home/com010/m050/test3.py", line 2, in <module>
driver = webdriver.Firefox()
File "/home/com010/.local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 142, in __init__
self.service.start()
File "/home/com010/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
-
- Similar Topics
- ตอบกลับ
- แสดง
- โพสต์ล่าสุด
-
-
โพสต์ใหม่ รวมบทความสอน selenium Webdriver ภาษา Python
โดย nuattawoot » 28/11/2017 2:34 pm » ใน Programming - C/C++ & java & Python - 0 ตอบกลับ
- 1354 แสดง
-
โพสต์ล่าสุด โดย nuattawoot
28/11/2017 2:34 pm
-
-
-
โพสต์ใหม่ รวมบทความสอน selenium Webdriver ภาษา Python
โดย nuattawoot » 23/11/2017 1:37 pm » ใน Python Knowledge - 0 ตอบกลับ
- 1396 แสดง
-
โพสต์ล่าสุด โดย nuattawoot
23/11/2017 1:37 pm
-
ผู้ใช้งานขณะนี้
สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 90