โค้ด: เลือกทั้งหมด
assertTrue
ถ้าไม่ได้ใช้ก้อไม่ต้องใส่เข้าไป
Moderator: mindphp, ผู้ดูแลกระดาน
โค้ด: เลือกทั้งหมด
time.sleep(5)
driver.is_element_present(By.NAME, "post")
โค้ด: เลือกทั้งหมด
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'
โค้ด: เลือกทั้งหมด
try:
driver.find_element_by_id("ID")
return true
except NoSuchElementException:
return false
โค้ด: เลือกทั้งหมด
try:
time.sleep(5)
driver.is_element_present(By.NAME, "post")
except NoSuchElementException:
print ('กรุณาตรวจสอบสอบ')
โค้ด: เลือกทั้งหมด
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'
โค้ด: เลือกทั้งหมด
browser.find_element_by_xpath("//input[@value='โพสต์']").click();
โค้ด: เลือกทั้งหมด
def is_element_present(how, what):
try:
browser.find_element(by=how, value=what)
except NoSuchElementException:
return False
return True
โค้ด: เลือกทั้งหมด
# -*- 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()
สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 40