求助:python+selenium定位登录弹框元素
#!/usr/bin/env python#_*_coding:utf-8_*_
import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
driver=webdriver.Firefox()
driver.get('http://huoxiu.tv')
driver.maximize_window()
print(driver.title)
print('泛娱乐偶像资讯平台' in driver.title)
print('huoxiu' in driver.current_url)
driver.find_element_by_link_text('登录').click()
time.sleep(3)
a=driver.find_element_by_xpath('//iframe[@id="layui-layer-iframe1"]')
time.sleep(3)
driver.find_element_by_xpath('//*[@id="userNameLoginForm"]/div/input[@placeholder="手机号/账号/邮箱"]')
最后1句报错,定位不到元素
看了视频中演示是可以直接定位的,但是我这边的弹框直接定位不到,咨询了别人通过先定位登陆框,在定位元素
driver.switch_to_frame(driver.find_element_by_xpath('//iframe[@id="layui-layer-iframe1"]'))
time.sleep(3)
#driver.find_element_by_xpath('//*[@id="userNameLoginForm"]/div/input').send_keys('test30')
driver.find_element_by_xpath('//input[@placeholder="手机号/账号/邮箱"]').send_keys('test30')
什么视频呀分享一下呗:lol在学习呢 switch_window vhymn 发表于 2017-1-4 11:36
switch_window
你这个是提示框吧 driver.switch_to_frame(driver.find_element_by_xpath())
driver.switch_to_default_content() now_handle1=driver.current_window_handle
print(now_handle1)
driver.find_element_by_xpath("//img[@id='poparea3']").click()
now_handle=driver.current_window_handle
print(now_handle)
driver.switch_to_window(now_handle)
driver.find_element_by_xpath("//input[@value='207_NAT_ACTIVITY']").click()
driver.find_element_by_xpath("//button[@onclick='saveSubActivity();']").click()
C:\Users\CSSCA\Desktop\360反馈意见截图16410118437949.png
运行报错,selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //input[@value='207_NAT_ACTIVITY']
楼主怎么处理?
页:
[1]