在Selenium 1.x或2.x中是否有任何方法可以滚动浏览器窗口,以便XPath识别的特定元素可以在浏览器中查看?Selenium中有一个焦点方法,但它似乎没有在FireFox中物理滚动视图.有没有人对如何做到这一点有任何建议?
我需要这个的原因是我正在测试页面上元素的点击.不幸的是,除非元素可见,否则事件似乎不起作用.我无法控制单击该元素时触发的代码,因此我无法对其进行调试或修改,因此,最简单的解决方案是将项目滚动到视图中.
我们如何使用带有node.js的Selenium WebDriver(Selenium 2)来最大化firefox浏览器.我正在使用wd
Selenium WebDriver的包来编写测试.我曾尝试执行window.resizeTo(1366,768);
全光照eval
或execute
但没有奏效.
我正在使用Selenium WebDriver 2.25.0
我有一个长串测试,sendKeys()
需要太长时间.当我试图设置text
程序崩溃的值时.我知道Selenium sendKeys()
是测试实际用户输入的最佳方式,但对于我的应用程序,它需要花费太多时间.所以我试图避免它.
有没有办法立即设置价值?
看到这个简单的例子:
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
driver.get('http://www.google.com');
// find the search input field on google.com
inputField = driver.findElement(webdriver.By.name('q'));
var longstring = "test"; // not really long for the sake of this quick example
// this works but is slow
inputField.sendKeys(longstring);
// no error but no values set
inputField.value = longstring;
// Output: TypeError: Object [object Object] has no method 'setAttributes'
inputField.setAttributes("value", longstring);
Run Code Online (Sandbox Code Playgroud) 我试图点击文本克隆概念的跨度.以下是html
<ul class="context-menu-list context-menu-root" style="width: 210px; top: 500px; left: 231px; z-index: 2;">
<li class="context-menu-item">
<li class="context-menu-item">
<li class="context-menu-item disabled">
<li class="context-menu-item">
<li class="context-menu-item icon icon-evn-icon-clone-concept">
<span>Clone concept</span>
</li>
<li class="context-menu-item">
<li class="context-menu-item icon icon-delete disabled">
</ul>
Run Code Online (Sandbox Code Playgroud)
我使用的javascript代码是:
driver.findElement(By.xpath("//span[text()='Clone concept']")).click();
Run Code Online (Sandbox Code Playgroud)
我通过firepath验证了这是元素的权利.
我还确保元素是可见的链接如何强制Selenium WebDriver点击当前不可见的元素?
这是计算的css
font-family Verdana,?Arial,?Helvetica,?sans-serif
.context-menu-list Verdana,?Arial,?Helvetica,?sans-serif
jquery...enu.css (line 15)
body Arial,?Helvetica,?sans-serif
swa.css (line 3)
font-size 11px
.context-menu-list 11px
jquery...enu.css (line 15)
list-style-type none
.context-menu-list none
jquery...enu.css (line 15)
Run Code Online (Sandbox Code Playgroud)
还尝试了以下代码:
WebElement foo = driver.findElement(By.xpath("//span[text()='Clone concept']"));
Actions bar = …
Run Code Online (Sandbox Code Playgroud) 这个页面的主菜单(linio)有11个链接.只对9感兴趣(灰色背景和显示子菜单时).
我想从9个选项中单击子菜单中的每个元素.期望的过程是:
1.-第一部分:"Celulares y Tablets".
2.-转到:"Celulares y智能手机".请单击并查看此页面.
3.-提取一些数据(选中,我已经能够这样做了).
4.-转到"Celulares y Tablets"中的下一个子菜单.其中:"Accesorios Celular".
5.-提取一些数据,然后转到下一个子菜单.完成本节中的所有子菜单后,我将进入下一个大部分:"TV-Audio-y-Foto".
等9个部分.
HTML结构
查看源代码,我已经到了这个:
1.-主标题:主标题位于'nav'标记内:
<nav id="headerMainMenu>
Run Code Online (Sandbox Code Playgroud)
2.-'nav'标签内部是'ul',内部的每个'il'对于9个部分中的每一个都有'id'和'id':
<nav id="headerMainMenu>
<ul>
<il id = "category-item-celulares-y-tablets"><a href="..."></il>
<il id = "category-item-celulares-y-tablets"><a href="..."></il>
<il id = "category-item-celulares-y-tablets"><a href="..."></il>
</ul>
</nav>
Run Code Online (Sandbox Code Playgroud)
3.-在il元素中,有div元素包含我们需要的链接:请注意<a>
使用class ="subnav__title".
<nav id="headerMainMenu>
<ul>
<il id = "category-item-celulares-y-tablets"><a href="...">
<div class="col-3">
<a href="..."class="subnav__title">TV y Video</a>
</il>
<il id = "category-item-celulares-y-tablets"><a href="..."></il>
<il id = "category-item-celulares-y-tablets"><a href="..."></il>
</ul>
</nav>
Run Code Online (Sandbox Code Playgroud)
4.-使用RSelenium转到每个部分:
library(RSelenium)
library(rvest)
#start RSelenium
checkForServer()
startServer() …
Run Code Online (Sandbox Code Playgroud) 硒-2.37.0
Firefox 24.0(虽然也尝试过 Chrome)
Mac OS X 山狮 10.8.5
涉及 Windows、特定于 Windows 的自动化工具/库或 Mac OS X 以外的操作系统的解决方案是不可接受的答案
首先我要指出的是,Stackoverflow 上经常有人提出非常类似的问题,我已经检查了每个提供的答案,但没有一个适用于 CuteWebUI_Uploader_Resource AJAX 文件上传器,我将在下面详细说明。
我有一个包含数据和文件的企业 Java Web 应用程序,希望自动映射并上传该 Web 应用程序中选定的数据和文件子集(到)单独的 ASP.NET Web 应用程序,该应用程序使用 CuteWebUI 工具包和 CuteWebUI_Uploader_Resource来自可爱软件。
在撰写本文时,http://cutesoft.net服务器已关闭几天;谷歌搜索提供了一些 CuteSoft 论坛点击可能有助于解决此问题,但我目前无法访问它们。
与许多文件上传器一样,CuteWebUI AJAX 文件上传器有一个浏览按钮和一个上传按钮。
我希望能够直接上传到 CuteWebUI AJAX 文件上传器,而无需使用“浏览”按钮(并且无需使用 Mac OS X 上的“浏览”对话框玩任何花招,因为浏览器无法使用我希望上传的文件在本地文件系统上,而是存储在可通过 Java 访问 Java Web 应用程序的服务器上,尽管为了测试我可以将它们放在本地文件系统上,如下所示)。
我很高兴其他文件上传者已经多次回答了这个问题(请参阅本文末尾的详尽列表),并且通常描述为大多数文件上传者的解决方案的过程大致如下:
识别由浏览按钮填充的文件上传路径(有时隐藏)的输入字段。有时需要使用 JavascriptExecutor 取消隐藏它并确保它是一个文本字段,然后使用 sendKeys 填充它。
找到匹配的“提交”上传按钮并单击()。
这不适用于 CuteWebUI AJAX 文件上传器。
我所针对的系统确实有一个 INPUT 元素,从名称上看,它用于存储文件上传路径,但事实上,当我手动尝试它时(并使用 Firebug 和 Selenium IDE 检查它),它的值并未填充根本没有,而是出现一个全新的可上传文件临时表。
以下 HTML …
我正在使用Selenium来保存网页.单击某些复选框后,网页内容将发生变化.我想要的是单击一个复选框,然后保存页面内容.(复选框由JavaScript控制.)
首先我用过:
driver.find_element_by_name("keywords_here").click()
Run Code Online (Sandbox Code Playgroud)
它以错误结束:
NoSuchElementException
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用"xpath",使用隐式/显式等待:
URL = “the url”
verificationErrors = []
accept_next_alert = True
aaa = driver.get(URL)
driver.maximize_window()
WebDriverWait(driver, 10)
#driver.find_element_by_xpath(".//*[contains(text(), ' keywords_here')]").click()
#Or:
driver.find_element_by_xpath("//label[contains(text(),' keywords_here')]/../input[@type='checkbox']").click()
Run Code Online (Sandbox Code Playgroud)
它给出了一个错误:
ElementNotVisibleException
Run Code Online (Sandbox Code Playgroud)
帖子
如何强制Selenium WebDriver点击当前不可见的元素?
建议它应该在点击之前使复选框可见,例如使用:
execute_script
Run Code Online (Sandbox Code Playgroud)
这个问题可能听起来很愚蠢,但是如何从页面源代码中找到"execute_script"复选框可见性的正确句子?
除此之外,还有另一种方式吗?
谢谢.
顺便说一句,行html代码看起来像:
<input type="checkbox" onclick="ComponentArt_HandleCheck(this,'p3',11);" name="keywords_here">
Run Code Online (Sandbox Code Playgroud)
它的xpath看起来像:
//*[@id="TreeView1_item_11"]/tbody/tr/td[3]/input
Run Code Online (Sandbox Code Playgroud) javascript python selenium selenium-webdriver execute-script
selenium ×5
javascript ×2
automation ×1
file-upload ×1
firefox ×1
java ×1
node.js ×1
python ×1
rselenium ×1
scroll ×1
webdriver ×1