需要一些关于将JavaScript与Python/Selenium WebDriver一起使用的建议
Need some advice on using JavaScript with Python/Selenium WebDriver
我一直在搜索堆栈溢出来寻找这个问题的答案。我正在尝试使用Selenium WebDriver单击iframe并填写注册表上的字段。由于 Python 本身返回错误"无法定位元素",我现在尝试使用 JavaScript 进入该领域。
新错误是"引发exception_class(消息、屏幕、堆栈跟踪)selenium.common.exceptions.WebDriverException: Message: u'document.getElementById(...) is null' ;"
关于我做错了什么有什么建议吗?
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
import string
import random
def id_generator(size=6, chars=string.ascii_uppercase):
return ''.join(random.choice(chars) for x in xrange(size))
# Create a new instance of the Firefox driver
driver = webdriver.Firefox()
driver.get("http://bostinno.streetwise.co")
driver.find_element_by_link_text("Sign-up").click()
WebDriverWait(driver, 30)
driver.execute_script("document.getElementById('User_firstName').click()")
type(id_generator())
这
应该可以用Selenium API switchto()
来实现,它不需要任何JavaScript。它可能看起来像这样:
# move into the iframe
iframe = driver.find_elements_by_tag_name('iframe')[0]
driver.switch_to_frame(iframe)
# interact with your element inside the iframe
driver.find_element_by_link_text("Sign-up").click()
driver.find_element_by_id("User_firstName").click()
# do any other steps you need...
# move back out of iframe
driver.switch_to_default_content()
相关文章:
- 转义符不能与innerHTML一起使用
- Selenium WebDriver and JavaScript change
- 高亮显示与数组字符串一起使用时文本插件中断
- Webdriver.io pageObject模式-通过传递参数来定义元素选择器
- setTimeout可以与闭包内的函数一起使用吗
- 将依赖外部库的UMD模块与browserfy捆绑在一起
- Highcharts colorsByPoint与系列中的线性渐变一起使用时不起作用
- 如何将js库与typescript一起使用
- 将webpack和babel与父项目目录中的文件一起使用
- 将 Drag&Drop 与 jsTree 和 DataTables 一起使用
- Javascript-如何让脚本与Ajax请求的数据一起运行
- 将两个ext.TabPanels滚动到一起
- 将jQuery UI Timepicker Addon与React一起使用
- 什么是curl以及如何将其与nodejs一起使用
- Javascript”;onmousemove”;事件无法与类一起使用
- 将require('..')与变量一起使用与在webpack中使用字符串相比
- 如何在php中创建一个函数,该函数与文本区域一起工作,通过输入类似[color:red]的内容来打印具有等效颜色的文本
- 三角库可以与firefox一起使用,但不能在Chrome中使用
- 需要一些关于将JavaScript与Python/Selenium WebDriver一起使用的建议
- Selenium webdriver不能与jasmine一起工作