有谁知道是否可以使用Selenium WebDriver截取屏幕截图?(注:不是Selenium RC)
selenium selenium-webdriver ashot takesscreenshot selenium-shutterbug
我正在使用Python绑定来运行Selenium WebDriver.
from selenium import webdriver
wd = webdriver.Firefox()
Run Code Online (Sandbox Code Playgroud)
我知道我可以抓住这样的一个元素......
elem = wd.find_element_by_css_selector('#my-id')
Run Code Online (Sandbox Code Playgroud)
而且我知道我可以获得完整的页面来源...
wd.page_source
Run Code Online (Sandbox Code Playgroud)
但无论如何要获得"元素来源"?
elem.source # <-- returns the HTML as a string
Run Code Online (Sandbox Code Playgroud)
用于Python的selenium webdriver文档基本上不存在,我在代码中看不到任何似乎启用该功能的内容.
有关访问元素(及其子元素)的HTML的最佳方法的任何想法?
python selenium automated-tests webdriver selenium-webdriver
我是编程的新手,Python大约2个月前开始使用Python文本,正在浏览Sweigart的自动化无聊的东西.我正在使用IDLE并且已经安装了selenium模块和Firefox浏览器.每当我尝试运行webdriver函数时,我都会得到:
from selenium import webdriver
browser = webdriver.Firefox()
Run Code Online (Sandbox Code Playgroud)
例外: -
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x00000249C0DA1080>>
Traceback (most recent call last):
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
self.stop()
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x00000249C0E08128>>
Traceback (most recent call last):
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
self.stop()
File …Run Code Online (Sandbox Code Playgroud) 我只在Chrome中看到这一点.
完整的错误消息显示:
"org.openqa.selenium.WebDriverException:元素在点(411,675)处不可点击.其他元素将收到点击:..."
"将接收点击"的元素位于相关元素的一侧,而不是位于其上方且不与其重叠,而不是在页面上移动.
我试过添加一个偏移量,但这也不起作用.该项目位于显示的窗口上,无需滚动.
我正在尝试为浏览器自动测试套件和能够抓取的无头浏览器平台列出可能的解决方案列表.
浏览器测试/清除:
JAVASCRIPT
Node.js的
我一直在用Chromedriver测试Selenium,我注意到有些页面可以检测到你正在使用Selenium,即使根本没有自动化.即使我只是通过Selenium和Xephyr使用chrome手动浏览我经常会得到一个页面,说明检测到可疑活动.我检查了我的用户代理和浏览器指纹,它们与普通的Chrome浏览器完全相同.
当我在普通镀铬中浏览这些网站时,一切正常,但是当我使用Selenium的时候,我已经检测到了.
从理论上讲,chromedriver和chrome应该看起来与任何网络服务器完全相同,但不知怎的,他们可以检测到它.
如果你想要一些测试代码试试这个:
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=1, size=(1600, 902))
display.start()
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--disable-extensions')
chrome_options.add_argument('--profile-directory=Default')
chrome_options.add_argument("--incognito")
chrome_options.add_argument("--disable-plugins-discovery");
chrome_options.add_argument("--start-maximized")
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.delete_all_cookies()
driver.set_window_size(800,800)
driver.set_window_position(0,0)
print 'arguments done'
driver.get('http://stubhub.com')
Run Code Online (Sandbox Code Playgroud)
如果您浏览stubhub,您将在一两个请求中被重定向和"阻止".我一直在研究这个,我无法弄清楚他们如何判断用户是否正在使用Selenium.
他们是如何做到的呢?
编辑更新:
我在Firefox中安装了Selenium IDE插件,当我在普通的firefox浏览器中使用附加插件访问stubhub.com时,我被禁止了.
编辑:
当我使用Fiddler来查看来回发送的HTTP请求时,我注意到"假浏览器"的请求通常在响应头中有"无缓存".
编辑:
这样的结果是否有办法检测到我在Javascript的Selenium Webdriver页面中建议无法检测何时使用webdriver.但是这个证据表明不然.
编辑:
该网站将指纹上传到他们的服务器,但我检查了使用chrome时硒的指纹与指纹相同.
编辑:
这是他们发送到服务器的指纹有效负载之一
{"appName":"Netscape","platform":"Linuxx86_64","cookies":1,"syslang":"en-US","userlang":"en-US","cpu":"","productSub":"20030107","setTimeout":1,"setInterval":1,"plugins":{"0":"ChromePDFViewer","1":"ShockwaveFlash","2":"WidevineContentDecryptionModule","3":"NativeClient","4":"ChromePDFViewer"},"mimeTypes":{"0":"application/pdf","1":"ShockwaveFlashapplication/x-shockwave-flash","2":"FutureSplashPlayerapplication/futuresplash","3":"WidevineContentDecryptionModuleapplication/x-ppapi-widevine-cdm","4":"NativeClientExecutableapplication/x-nacl","5":"PortableNativeClientExecutableapplication/x-pnacl","6":"PortableDocumentFormatapplication/x-google-chrome-pdf"},"screen":{"width":1600,"height":900,"colorDepth":24},"fonts":{"0":"monospace","1":"DejaVuSerif","2":"Georgia","3":"DejaVuSans","4":"TrebuchetMS","5":"Verdana","6":"AndaleMono","7":"DejaVuSansMono","8":"LiberationMono","9":"NimbusMonoL","10":"CourierNew","11":"Courier"}}
Run Code Online (Sandbox Code Playgroud)
它的硒和铬相同
编辑:
VPN仅供一次使用,但在加载第一页后会被检测到.很明显,正在运行一些javascript来检测Selenium.
javascript python selenium google-chrome selenium-chromedriver
我正在寻找一种在Selenium中输入和输入或返回键的快捷方式.不幸的是,我试图测试的表单(不是我自己的代码,所以我无法修改)没有提交按钮.手动使用时,我只需输入ENTER或RETURN.我需要知道如何使用Selenium type命令执行此操作,因为没有可单击的按钮.
当我使用MSTest Framework,并复制Selenium IDE为我生成的代码时,MSTest无法识别[TearDown]和[SetUp].有什么替代方案?
我正在尝试使用Selenium测试复杂的javascript界面(使用Python界面,以及跨多个浏览器).我有许多形式的按钮:
<div>My Button</div>
Run Code Online (Sandbox Code Playgroud)
我希望能够根据"我的按钮"搜索按钮(或者不区分大小写的部分匹配,例如"我的按钮"或"按钮")
我发现这非常困难,在某种程度上我觉得我错过了一些明显的东西.我到目前为止最好的事情是:
driver.find_elements_by_xpath('//div[contains(text(), "' + text + '")]')
Run Code Online (Sandbox Code Playgroud)
但是,这是区分大小写的.我尝试过的另一件事是遍历页面上的所有div,并检查element.text属性.但是,每次你得到表格的情况:
<div class="outer"><div class="inner">My Button</div></div>
Run Code Online (Sandbox Code Playgroud)
div.outer还有"My Button"作为文本.为了解决这个问题,我试图查看div.outer是否是div.inner的父节点,但是无法弄清楚如何做到这一点(element.get_element_by_xpath('..')返回一个元素的父节点,但它测试不等于div.outer).此外,迭代浏览页面上的所有元素似乎非常慢,至少使用Chrome webdriver.
想法?
编辑:这个问题有点模糊.在这里询问(并回答)一个更具体的版本:如何在不包含子元素文本的情况下获取Selenium WebDriver中的元素文本(通过Python api)?
你如何使Selenium 2.0等待页面加载?
selenium ×10
python ×4
webdriver ×2
ashot ×1
automation ×1
c# ×1
casperjs ×1
enter ×1
firefox ×1
geckodriver ×1
java ×1
javascript ×1
keypress ×1
mstest ×1
phantomjs ×1
scrapy ×1
web-scraping ×1