Python Selenium在wordpress管理页面中不起作用

时间:2017-09-10 05:31:29

标签: python selenium

selenium在我的wordpress管理面板中不起作用(不能选择选项作为image2)。请帮我!我是编程的初学者。

image1 : Wordpress Admin Page

image2 : After CSV File Uploaded

python:3.6 Selenium:最新的

# coding: utf-8   
from selenium.webdriver.support.select import Select
from selenium import webdriver
import pyautogui
from time import sleep

browser = webdriver.Chrome()

# WordPress admin page ( image1 )
browser.get(wai1url)
sleep(5)

# upload csv file
browser.find_element_by_link_text(u"ファイルをアップロードする").click()
sleep(2)
pyautogui.typewrite('link_20')
sleep(3)
pyautogui.press('down')
sleep(1)
pyautogui.press('return')
sleep(2)

#
# after csv file uploaded ( image2 )
#

# page scroll
browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")

# below code worked
browser.find_element_by_link_text(u"既存の項目").click()
sleep(3)
browser.find_element_by_link_text(u"新規の項目").click()
sleep(3)

# But below code doesn't work
select = Select(browser.find_element_by_name('custom_type_selector'))

for index in range(len(select.options)):
    select = Select(browser.find_element_by_name('custom_type_selector'))
    select.select_by_index(4) # select Users 

问题部分的HTML在下面。

<select name="custom_type_selector" id="custom_type_selector" class="wpallimport-post-types">

<option value="post" data-imagesrc="dashicon dashicon-post" selected="selected">投稿</option>

<option value="page" data-imagesrc="dashicon dashicon-page" >固定ページ</option>

<option value="taxonomies" data-imagesrc="dashicon dashicon-taxonomies" >Taxonomies</option>

<option value="import_users" data-imagesrc="dashicon dashicon-import_users" >Users</option>

</select>

我尝试了一些方法。例如......

s1 = Select(browser.find_element_by_id('custom_type_selector'))
s1.select_by_index(4)

结果&gt;&gt;&gt; selenium.common.exceptions.UnexpectedTagNameException:消息:选择仅适用于