标签: selenium-webdriver

如何使用Java在Selenium WebDriver中选择下拉列表值

我是selenium的新手,目前正在研究selenium webdriver我想从下拉列表中选择一个值.id = periodId和选项很多,我试图选择过去52周.

这是Html标签:

<select id="periodId" name="period" style="display: none;">
    <option value="l4w">Last 4 Weeks</option>
    <option value="l52w">Last 52 Weeks</option>
    <option value="daterange">Date Range</option>
    <option value="weekrange">Week Range</option>
    <option selected="" value="monthrange">Month Range</option>
    <option value="yeartodate">Year To Date</option>
</select>
Run Code Online (Sandbox Code Playgroud)

请建议我点击下拉列表的一些方法.

我尝试使用上面的示例行但是得到错误,例如Element当前不可见,因此可能无法与命令持续时间或超时交互:32毫秒下拉值是jquery multiselect小部件格式

java selenium-webdriver

45
推荐指数
3
解决办法
35万
查看次数

有没有办法使用Selenium和Python绑定执行鼠标悬停(悬停在元素上)?

在这里阅读,显然曾经是一个带有悬停方法的RenderedWebElement类.但是,它专门用于Java(在这里搜索python绑定文档无济于事),因此已被弃用于Java.

无法使用action_chains(方法列表)执行悬停,也不能使用webelement(方法列表)对象执行悬停.

有关如何为python执行此操作的任何想法?在这里,但它使用RenderedWebElement,因此没有太多帮助.

Python 2.7,Windows Vista,Selenium 2,Python绑定

编辑:对于selenium.selenium.selenium对象有一个方法"mouse_over",但我无法想象一种方法来创建一个实例,而不必运行独立服务器.

问题已经回答:如果您有误解,请仔细阅读标记为答案的回复评论!

python selenium python-bindings selenium-webdriver

44
推荐指数
2
解决办法
6万
查看次数

如何在Selenium WebDriver Java中使用JavaScript

我想使用Java与WebDriver(Selenium 2)一起使用JavaScript.

我已经按照一些指南和" 入门"页面进行操作:第一行有一条指令可以运行:

$ ./go webdriverjs
Run Code Online (Sandbox Code Playgroud)

我的问题:从哪个文件夹/位置运行/执行上面提到的命令?

javascript java selenium-webdriver

44
推荐指数
2
解决办法
24万
查看次数

python selenium webscraping "NoSuchElementException" not recognized

有时在页面上我会寻找一个可能存在或不存在的元素.我想尝试/捕获这个案例,NoSuchElementException当某些HTML元素不存在时,selenium会抛出.原始例外:

NoSuchElementException: Message: u'Unable to locate element: {"method":"css selector","selector":"#one"}' ; Stacktrace: 
    at FirefoxDriver.prototype.findElementInternal_ (file:///var/folders/6q/7xcjtgyj32nfc2yp_y5tr9pm0000gn/T/tmp63Mz2a/extensions/fxdriver@googlecode.com/components/driver_component.js:8899)
    at FirefoxDriver.prototype.findChildElement (file:///var/folders/6q/7xcjtgyj32nfc2yp_y5tr9pm0000gn/T/tmp63Mz2a/extensions/fxdriver@googlecode.com/components/driver_component.js:8911)
    at DelayedCommand.prototype.executeInternal_/h (file:///var/folders/6q/7xcjtgyj32nfc2yp_y5tr9pm0000gn/T/tmp63Mz2a/extensions/fxdriver@googlecode.com/components/command_processor.js:10840)
    at DelayedCommand.prototype.executeInternal_ (file:///var/folders/6q/7xcjtgyj32nfc2yp_y5tr9pm0000gn/T/tmp63Mz2a/extensions/fxdriver@googlecode.com/components/command_processor.js:10845)
    at DelayedCommand.prototype.execute/< (file:///var/folders/6q/7xcjtgyj32nfc2yp_y5tr9pm0000gn/T/tmp63Mz2a/extensions/fxdriver@googlecode.com/components/command_processor.js:10787) 
Run Code Online (Sandbox Code Playgroud)

具有讽刺意味的是,它不会让我抓住它之前抛出的这个例外吗?代码在这里:

elt = driver.find_element_by_css_selector('.information')
try:
    dat1 = elt.find_element_by_css_selector('#one').text
    dat2 = elt.find_elements_by_css_selector('#two')[1].text
    text = dat1 + dat2
except NoSuchElementException:
    text = elt.find_element_by_css_selector('#all').text
    item.set_description(text)
Run Code Online (Sandbox Code Playgroud)

错误在这里:

NameError: name 'NoSuchElementException' is not defined
Run Code Online (Sandbox Code Playgroud)

谷歌搜索/文档没有任何结果......而且让我感到奇怪的是,硒很好地抛出一个例外但却无法捕获它.

python selenium exception selenium-webdriver

43
推荐指数
1
解决办法
5万
查看次数

Selenium WebDriver和DropDown Boxes

如果我想选择下拉框的选项,有几种方法可以做到这一点.我一直用:

driver.findElement(By.id("selection")).sendKeys("Germany");
Run Code Online (Sandbox Code Playgroud)

但这并不是每次都有效.有时选择另一个选项.所以我google了一下,发现这段代码每次都有效:

WebElement select = driver.findElement(By.id("selection"));
    List<WebElement> options = select.findElements(By.tagName("option"));
    for (WebElement option : options) {
        if("Germany".equals(option.getText()))
            option.click();
    }
Run Code Online (Sandbox Code Playgroud)

但这确实很慢.如果我有一个包含很多项目的长列表,那真的需要花费太多时间.所以我的问题是,是否有一个解决方案,每次都有效并且速度快?

java selenium webdriver selenium-webdriver drop-down-menu

42
推荐指数
2
解决办法
15万
查看次数

Selenium waitForElement

如何为Selenium编写函数以等待Python中只有类标识符的表?我有一个学习使用Selenium的Python webdriver功能的魔鬼.

python automation automated-tests selenium-webdriver

42
推荐指数
3
解决办法
9万
查看次数

Firefox webdriver始终打开第一个运行页面

如何为FF暂时禁用这个"首次运行"页面?

创建FF驱动程序时,它会打开选​​项卡,其中包含 - https://www.mozilla.org/en-US/firefox/42.0/firstrun/learnmore/ 以及带有目标页面的附加选项卡.

firefox selenium selenium-firefoxdriver selenium-webdriver

42
推荐指数
4
解决办法
3万
查看次数

SyntaxError:在严格模式下使用const?

我想用selenium-webdriver登录facebook.com.

var webdriver = require('selenium-webdriver'),
    By = require('selenium-webdriver').By,
    until = require('selenium-webdriver').until;

var driver = new webdriver.Builder()
    .forBrowser('firefox')
    .build();

driver.get('https://www.facebook.com/login');
driver.findElement(By.id('email')).sendKeys('****');
driver.findElement(By.id('pass')).sendKeys('*****');
driver.findElement(By.id('loginbutton')).click();

driver.findElement(By.linkText('Settings')).then(function(element) {
  console.log('Yes, found the element');
}, function(error) {
  console.log('The element was not found, as expected');
});
driver.quit();
Run Code Online (Sandbox Code Playgroud)

这是错误的:

/home/shubham/node_modules/selenium-webdriver/index.js:25
const builder = require('./builder');
^^^^^
SyntaxError: Use of const in strict mode.
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/shubham/Music/amazon_login/test_22_4_16/sel_login.js:1:79)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js …
Run Code Online (Sandbox Code Playgroud)

selenium node.js selenium-webdriver

42
推荐指数
2
解决办法
11万
查看次数

Selenium-Debugging:元素在点(X,Y)处不可点击

我试图通过Selenium 刮掉这个网站.

我想点击"下一页"按钮,为此我这样做:

 driver.find_element_by_class_name('pagination-r').click()
Run Code Online (Sandbox Code Playgroud)

它适用于许多页面但不适用于所有页面,我收到此错误

WebDriverException: Message: Element is not clickable at point (918, 13). Other element would receive the click: <div class="linkAuchan"></div>
Run Code Online (Sandbox Code Playgroud)

总是为这个页面

我读了这个问题

我试过这个

driver.implicitly_wait(10)
el = driver.find_element_by_class_name('pagination-r')
action = webdriver.common.action_chains.ActionChains(driver)
action.move_to_element_with_offset(el, 918, 13)
action.click()
action.perform()
Run Code Online (Sandbox Code Playgroud)

但我得到了同样的错误

python selenium web-scraping selenium-firefoxdriver selenium-webdriver

42
推荐指数
3
解决办法
3万
查看次数

DeslenCapabilities在Selenium WebDriver中的用途是什么?

DeslenCapabilities在Selenium WebDriver中的用途是什么?

什么时候想用这个怎么样?

回答示例将不胜感激.

selenium-webdriver

41
推荐指数
3
解决办法
12万
查看次数