from selenium import webdriver
import time
from selenium.webdriver.support.select import Select
driver = webdriver.Firefox(executable_path='/home/cwb/桌面/celery_used/for_test/driver/Firefox/geckodriver')
driver.get('http://192.168.1.106/index.php?m=user&c=public&a=login')
# 窗口最大化
driver.maximize_window()
driver.find_element_by_id('username').clear() # 清除輸入框中的內(nèi)容
driver.find_element_by_id('username').send_keys('cwb') # 在輸入框中填入
driver.find_element_by_id('password').clear()
driver.find_element_by_id('password').send_keys('123456')
driver.find_element_by_class_name('login_btn.fl').submit()
time.sleep(10)
driver.find_element_by_xpath('//div[@class="w1100"]/div[1]/a/img').click()
driver.implicitly_wait(10) # 隱式等待(也就是在網(wǎng)頁加載的時候等待,10秒,如果網(wǎng)頁還未加載完成,直接報錯)
driver.find_element_by_xpath('/html/body/div[5]/div/div[2]/div/a/img').click()
# 頁面點擊,跳轉(zhuǎn)到新窗口
driver.switch_to.window(driver.window_handles[-1])
# 加入購物車
driver.find_element_by_id('joinCarButton').click()
# 去結(jié)算
driver.find_element_by_class_name('shopCar_T_span3').click()
driver.implicitly_wait(5)
driver.find_element_by_class_name('shopCar_btn_03.fl').click()
driver.implicitly_wait(5)
# 判斷是否要添加收貨地址
try:
driver.find_element_by_class_name('add-address-1.selected')
except:
driver.find_element_by_class_name('add-address').click()
driver.find_element_by_class_name('add-new-name-span').send_keys('mark')
driver.find_element_by_xpath('/html/body/div[1]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[2]/td[2]/div/div/div[2]/input').send_keys('15517875853')
# 定位到對應(yīng)的下拉框標(biāo)簽
select = driver.find_element_by_class_name('add-new-area-select')
# 通過Select對象來實現(xiàn)通過
#顯示文本(select_by_visible_text),下標(biāo)(select_by_index),下拉選項對應(yīng)的value值(select_by_value),等方法,
Select(select).select_by_visible_text('北京市')
select = driver.find_elements_by_class_name('add-new-area-select')
Select(select[1]).select_by_visible_text('北京市')
Select(select[2]).select_by_visible_text('東城區(qū)')
driver.find_element_by_class_name('add-new-name-span-2').send_keys('supermarket')
driver.find_element_by_class_name('add-new-name-span-3').send_keys('400590')
driver.find_element_by_class_name('aui_state_highlight').click()
selenium使用下拉框選項
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 又要開篇叨叨 昨天沒有更新,但因為下大雨沒擼串,陪孩子玩了下前一天寫的Flask開發(fā)猜數(shù)字小游戲---聰明的奧特曼...
- 3.5.2 選擇框進(jìn)行選擇 單選框單選框(Radio Button)像這樣:image.png 要對選擇框進(jìn)行選擇...
- 寫小程序時候,經(jīng)常遇到使用下拉框選項,不過每次都手寫很麻煩,所有我就發(fā)一個例子吧,因為我包在其他模塊中,所有樣式不...
- 聯(lián)動下拉框可以滿足省市區(qū)級聯(lián)或者多級級聯(lián)異步加載數(shù)據(jù)操作。演示地址:http://fslayui.itcto.cn...
- firefox select框刷新無法選擇帶有“selected”屬性的option選項,可是chrome是好用的...