ส่วนของโค้ด selenium test โดยผมใช้ forech มาใช้ในการวนลูป แล้วใช้ if ในการคลิ๊กเข้าไปในแต่ละลิ้งค์ แต่ผลที่ได้กลับ Error จะต้องแก้ไขยังครับ
โค้ด: เลือกทั้งหมด
driver.get('https://www.mindphp.com/forums/index.php')
link = driver.find_elements_by_css_selector('a.topictitle')
for x in range(0,len(link)):
if link[x].click():
driver.find_element_by_link_text(u"เว็บบอร์ด").click()
โค้ด: เลือกทั้งหมด
/usr/bin/python2.7 /home/com010/PycharmProjects/mdsoft_module/testselenium/seleniumtest.py
Traceback (most recent call last):
File "/home/com010/PycharmProjects/mdsoft_module/testselenium/seleniumtest.py", line 120, in <module>
if link[x].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.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
(Session info: chrome=60.0.3112.78)
(Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 4.10.0-28-generic x86_64)
Process finished with exit code 1