【python+selenium的WebElement对象操作】教程文章相关的互联网学习教程文章

python – 强制Selenium等待AngularJS【代码】

我怎么能强制python Selenium等待一秒钟,直到AngularJS完成页面解析并加载它需要的东西. 或者如何在按钮单击后强制Selenium等待1秒钟,这会导致对服务器的ajax请求,由AngularJS处理.我需要在导航到其他页面之前进行服务器端操作.解决方法:通过Selenium访问AngularJS范围 – 很可能该状态已经在Scope / IsolatedScope中保存. 我构建了一些扩展来帮助解决这个问题,可以转换为python.webDriver.NgWaitFor(productDiv, "scope.Data.Id !...

python – 当Selenium打开Firefox时,为什么Firefox的url地址栏如此之小?【代码】

我正在尝试使用Selenium测试网页.我的代码如下.from selenium import webdriver from selenium.webdriver.common.keys import Keysdriver = webdriver.Firefox() driver.get("http://www.python.org") assert "Python" in driver.title elem = driver.find_element_by_name("q") elem.send_keys("selenium") elem.send_keys(Keys.RETURN) driver.close()当我运行上面的代码时,Firefox浏览器窗口会按预期弹出.但是,窗口字段的大小非...

Python,Selenium:’元素不再附加到DOM’【代码】

我正在抓一个网站,www.lipperleaders.com.我想提取新加坡的资金细节.我已成功实施下拉选择,并提取了提交选项后出现的第一页的内容.但是当我尝试转到下一页(通过使代码单击下一个按钮)时,我收到错误’元素不再附加到DOM’. 我的代码大约有100行,但我可以大致了解代码的执行流程:... # creating driver object and all the imports def main():...result = find_elements_by_tag_name('span') ...driver.find_e...

python – Selenium连接错误【代码】

有没有人遇到过这个错误?我刚刚开始在星期一收到这个错误.为什么连接有问题? Selenium将打开浏览器,但不会插入网址.C:\Python34\python.exe "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.0.5\helpers\pydev\pydevd.py" --multiproc --client 127.0.0.1 --port 49660 --file //HAL1/FTP-Directories/Comal-County/comal.pypydev debugger: process 5564 is connectingConnected to pydev debugger (build 139....

python – Felen焦点在Selenium chrome浏览器中【代码】

我正在使用Selenium从网站上抓取数据.该网站需要窗口焦点,以显示我需要的某些元素. 我希望能够在后台运行我的程序,而不必在窗口运行时对其进行聚焦. 有没有办法欺骗网站认为它专注于? 我正在使用硒铬驱动器. 编辑:Here’s a quick and dirty test I built. 查看代码on GitHub 收到window.onblur事件后,网站背景颜色将变为黑色,并在收到window.onfocus事件时返回白色. 我想假装那些事件,让浏览器认为它已经收到了焦点事件.解决方法...

Python Selenium返回文本,unicode对象不可调用【代码】

我正在尝试使用Selenium来自动化一些网页浏览.目前我正在尝试按类名访问特定元素并返回其中的文本(我在页面上选择的元素definetly中有文本)当我尝试在我的函数中返回它时,我得到TypeError: 'unicode' object is not callable我的功能代码如下:driver = webdriver.Chrome("my chromedriver installation path") driver.get("website URL")def getText():return driver.find_element_by_class_name("class with text").text()print ...

python – user:使用selenium传递代理【代码】

在程序中使用用户身份验证代理的最佳/最简单方法是什么?我目前有这个,但我需要在浏览器打开时填写用户名和密码.from selenium import webdriver PROXY = "123.123.123.243:80"chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("--proxy-server=http://{}".format(PROXY))print(chrome_options.arguments) chrome = webdriver.Chrome(executable_path="drivers/chromedriver",chrome_options=chrome_optio...

python – 我怎样才能选择一个html元素,无论它在selenium中的框架是什么?【代码】

我正在尝试选择一个位于iframe内部的元素,可能还有其他iframe. 是否有可能在(python)selenium中的某些(子)iframe中选择一个元素而不选择之前的iframe?有没有办法以某种方式“循环”每个iframe,并检查在哪里找到我的元素……? 如何在case元素和html的东西和iframe可能只是加载…?解决方法:不,无法通过Selenium与iframe中的任何WebElement进行交互,而无需切换到相应的iframe. 原因: 加载页面时,Selenium的焦点默认保留在Top Wind...

python – 如何关闭Selenium打开的所有窗口?【代码】

嘿伙计们,我现在正在使用Selenium RC做一些测试.我使用的驱动程序是python.但是现在,我遇到了一个问题,那就是:每次Selenium RC运行,并打开一个url,它会打开2个窗口,一个用于记录,另一个用于显示HTML内容.但我不能用脚本关闭它们. 这是我的剧本:#!/usr/bin/env python #-*-coding:utf-8-*- from selenium import seleniumdef main():sel = selenium('localhost', 4444, '*firefox', 'http://www.sina.com.cn/')sel.start()try:sel...

什么是Selenium / Webdriver的python绑定中的get_Text()等价物【代码】

我想从Selenium 1转到Selenium 2.我使用python绑定但是我找不到任何get_text()函数. 例如. selenium.find_elements_by_css_selector( “定位器”).get_text() Selenium / Webdriver的python绑定中是否有这样的功能?解决方法:使用’.text’属性.element.text

无法通过Python中的Selenium单击复选框【代码】

为什么我无法通过Python中的Selenium单击页面https://realty.yandex.ru/add上的以下复选框?import tracebackimport selenium.webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC import selenium.webdriver.support import selenium.webdriver.support.uiexplicit_wait_timeout_secs = 10def wait_for_element_presence(driver, find_type, web_element):...

python – 在Selenium上切换窗口【代码】

我在Python中使用Selenium和PhantomJS.我需要打开一个新窗口并控制它. 出于测试目的,我这样做:from selenium import webdriver driver = webdriver.PhantomJS()driver.get('http://www.google.com.br') handle = driver.execute_script('return window.open("http://www.pudim.com.br/", "any", "height = 450, width = 800, menubar=yes,scrollbars=yes,toolbar=yes,location=no,resizable=yes");') driver.switch_to.window(dri...

python – 使用PhantomJS Selenium处理重定向【代码】

我目前通过Python中的PhantomJS Selenium运行浏览器测试.desired_capabilities = dict(DesiredCapabilities.PHANTOMJS) desired_capabilities["phantomjs.page.settings.userAgent"] = ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36") driver = webdriver.PhantomJS(executable_path="./phantomjs", desired_capabilities=desired_capabilities)...

python – 在Phantomjs selenium中启用cookie【代码】

我想在我的armv7板上登录amazons3(使用url:’https://console.aws.amazon.com/iam/home?#security_credential‘).我使用了here的phantom2.0.1和selenium2.45.0. 我可以成功打开网站,但是当我在填写用户名和密码后“提交”时,网站会跳转到显示“请启用Cookie继续”的错误页面.所以我想知道如何在selenium中为phantomjs启用cookie.在我的ubuntu12.04中使用合适版本的phantomjs,我可以成功 我的部分代码如下:def __init__(self,user...

selenium3 + Python - 处理浏览器弹窗(转载)【图】

作者:Real_Tino 转载链接:https://blog.csdn.net/real_tino/article/details/59068827 我们在浏览网页时经常会碰到各种花样的弹窗,在做UI自动化测试的时候势必要处理这些弹窗,这里就介绍一下目前前端界两种弹窗的处理方法。 1.alert弹窗 这种弹窗是最简单的一种,Selenium里有自带的方法来处理它,用switch_to.alert先定位到弹窗,然后使用一系列方法来操作: accept - 点击【确认】按钮dismiss - 点击【取消】按钮(如有...