Tag: selenium

需要通过CSS在selenium中查找元素

我想在<h5>find这个链接的元素“us states”。 我正在Craigslist中尝试这个。 任何帮助将不胜感激 这是url: http : //auburn.craigslist.org/ <html class=""> <head> <body class="homepage w1024 list"> <script type="text/javascript"> <article id="pagecontainer"> <section class="body"> <table id="container" cellspacing="0" cellpadding="0" <tbody> <tr> <td id="leftbar"> <td id="center"> <td id="rightbar"> <ul class="menu collapsible"> <li class="expand s"> <li class="s"> <li class="s"> <h5 class="ban hot">us states</h5> <ul class="acitem" style="display: none;"> </li> <li class="s"> <li […]

如何使用Selenium WebDriver与java从下拉列表中select一个项目?

如何使用Selenium WebDriver与Java从性别(如男性,女性)下拉列表中select一个项目? 我已经试过了 WebElement select = driver.findElement(By.id("gender")); List<WebElement> options = select.findElements(By.tagName("Male")); for (WebElement option : options) { if("Germany".equals(option.getText())) option.click(); } 我上面的代码没有工作。

如何打破承诺链

我以这样的方式承诺, function getMode(){ var deferred = Promise.defer(); checkIf('A') .then(function(bool){ if(bool){ deferred.resolve('A'); }else{ return checkIf('B'); } }).then(function(bool){ if(bool){ deferred.resolve('B'); }else{ return checkIf('C'); } }).then(function(bool){ if(bool){ deferred.resolve('C'); }else{ deferred.reject(); } }); return deferred.promise; } checkIf返回一个promise,并且是checkIf 不能被修改 。 如何在第一场比赛中突围? (除了明确抛出错误以外的任何方式?)

如何在Selenium Webdriver中模拟HTML5拖放?

我正在使用Python 2.7和Selenium 2.44。 我想在Selenium WD中自动拖放操作,但根据其他相关文章,Selenium不支持HTML5中的操作 。 有没有什么办法来模拟Python中的拖放? 这是我试过的代码: driver = webdriver.Firefox() driver.get("http://html5demos.com/drag") target = driver.find_element_by_id("one") source = driver.find_element_by_id("bin") actionChains = ActionChains(driver) actionChains.drag_and_drop(target, source).perform() 并没有工作。

如何获取Selenium WebDriver中的元素的文本(通过Python API),而不包括子元素文本?

<div id="a">This is some <div id="b">text</div> </div> 获得“这是一些”是不平凡的。 例如,这返回“这是一些文本”: driver.find_element_by_id('a').text 一般来说,一个人如何得到一个特定元素的文本,而不包括它的孩子的文本? (我在下面提供了一个答案,但是如果有人能拿出一个不那么可怕的解决scheme,这个问题就会解决)。

JavaScript模拟右键单击代码

我正在使用Selenium编写一些UItesting,并使用Dojo工具包创buildJavaScript树控件。 我已经使用Dojo提供的示例为树的每个节点实现了一个上下文菜单,但是我需要Seleniumtesting来“调用”树节点上的右键单击,但是我无法使其工作。 testing不会通过JavaScript模拟右键单击事件,并且不显示上下文菜单。 有没有人有任何使用Dojo和Selenium右键单击上下文菜单的经验? 或者有什么想法如何做到这一点?

错误消息:“'chromedriver'可执行文件需要在path”

我正在使用python的selenium,并从本网站下载了我的Windows电脑的chromedriver: http ://chromedriver.storage.googleapis.com/index.html?path=2.15 / 下载zip文件后,我将zip文件解压到我的下载文件夹。 然后,我把可执行二进制文件(C:\ Users \ michael \ Downloads \ chromedriver_win32)的path放到环境variables“Path”中。 但是,当我运行下面的代码: from selenium import webdriver driver = webdriver.Chrome() …我不断收到以下错误信息: WebDriverException: Message: 'chromedriver' executable needs to be available in the path. Please look at http://docs.seleniumhq.org/download/#thirdPartyDrivers and read up at http://code.google.com/p/selenium/wiki/ChromeDriver 但是 – 如上所述 – 可执行文件是(!)在path中…这里发生了什么?

使用Java和Selenium WebDriver在表单和iframe中查找元素

我试图访问<form> <iFrame> <form> elements </form> </iFrame> </form> 。 你可以帮我访问这些“元素” ,我正在使用Selenium Webdriver和JAVA吗? 遇到的问题:能够到达目标页面(上述元素存在的地方),但这些元素不被我的代码识别。 XML结构概述: <body> <form action="https://abcd/efgh/" name="outerForm" method="post" target="iFrameTitle"> <iframe width="700" height="600" src="" title="Frame for Java Test" name="iFrameTitle" scrolling="auto" frameborder="0"> <form id="innerFormID" name="innerForm" action="/xxx/xxxx/yyyy/zzzz/" method="post" autocomplete="off"> <fieldset id="ncDetailsInner"> <div id="element1"> <label for="label1"> <abbr title="Required field">*</abbr></label> <input name="label2" type="text" maxlength="30" id="cardHolder" value="" > </div> <div id="element2"> […]

在Python中使用代理运行Selenium Webdriver

我想在Python中运行一个Selenium Webdriver脚本来完成一些基本的任务。 通过Selenium IDE界面(也就是说,当简单地获取GUI重复我的操作时),我可以让机器人完美地运行。 但是,当我将代码作为Python脚本导出并尝试从命令行执行时,Firefox浏览器将打开,但不能访问起始URL(错误返回到命令行,程序停止)。 这正在发生我无论什么网站等我试图访问。 为了演示目的,我在这里包含了一个非常基本的代码。 我不认为我正确地包含了代码的代码段,因为返回的错误似乎是由代理生成的。 任何帮助将非常感激。 下面的代码只是打开www.google.ie并search单词“selenium”。 对我来说,它打开一个空白的Firefox浏览器,并停止。 from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select from selenium.common.exceptions import NoSuchElementException import unittest, time, re from selenium.webdriver.common.proxy import * class Testrobot2(unittest.TestCase): def setUp(self): myProxy = "http://149.215.113.110:70" proxy = Proxy({ 'proxyType': ProxyType.MANUAL, 'httpProxy': myProxy, 'ftpProxy': myProxy, 'sslProxy': myProxy, 'noProxy':''}) self.driver […]

selenium元素不可见的例外

我一直负责编写一个parsing器来点击一个网站上的button,我有问题只点击其中一个button。 以下代码适用于除一个button之外的每个button。 这里是html: http : //pastebin.com/6dLF5ru8 这里是源html: http : //pastebin.com/XhsedGLb python代码: driver = webdriver.Firefox() … el = driver.find_element_by_id("-spel-nba") actions.move_to_element(el) actions.sleep(.1) actions.click() actions.perform() 我得到这个错误。 ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with 根据Saifur我刚刚尝试等待与相同的元素不可见的exception: wait = WebDriverWait(driver, 10) wait.until(EC.presence_of_element_located((By.XPATH, "//input[contains(@id,'spsel')][@value='nba']"))).click()