import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import re
import time
import autoit
wait = WebDriverWait
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs",prefs)
chrome_options.add_argument("start-maximized")
chrome_options.add_argument("--incognito")
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=r'C:\\chromedriver\\chromedriver.exe')
driver.maximize_window()
driver.get("https://www.arttoframe.com/search")
Search_Price = print(wait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="index"]/div[10]/div/div[4]/div/div[5]/div[2]/div[1]/div[2]/div/p[2]'))).text)
splitted = Search_Price.split()
first = splitted[0]
追踪(最近一次通话): 文件“C:\ Users \ Dell \ PycharmProjects \ untitled3 \ ATF_TestOrder.py”,第23行,in splitted = Search_Price.split() AttributeError:'NoneType'对象没有属性'split'
答案 0 :(得分:0)
@MikeScotty is right, print()
function return None
, don't use print()
here:
# wrong
# Search_Price = print(wait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="index"]/div[10]/div/div[4]/div/div[5]/div[2]/div[1]/div[2]/div/p[2]'))).text)
# right
Search_Price = wait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="index"]/div[10]/div/div[4]/div/div[5]/div[2]/div[1]/div[2]/div/p[2]'))).text
splitted = Search_Price.split()
first = splitted[0]
print(first)
Output
$900