有没有办法测试元素是否存在?任何findElement方法都会以异常结束,但这不是我想要的,因为它可能是一个元素不存在而且没关系,这不是测试的失败,因此异常不能成为解决方案.
我发现这篇文章:Selenium c#Webdriver:等到元素存在 但是这是C#而我不是很擅长.任何人都可以将代码翻译成Java吗?我很抱歉,我在Eclipse中尝试过但是我没有把它直接用到Java代码中.
这是代码:
public static class WebDriverExtensions{
public static IWebElement FindElement(this IWebDriver driver, By by, int timeoutInSeconds){
if (timeoutInSeconds > 0){
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
return wait.Until(drv => drv.FindElement(by));
}
return driver.FindElement(by);
}
}
Run Code Online (Sandbox Code Playgroud) 如果我想选择下拉框的选项,有几种方法可以做到这一点.我一直用:
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)
但这确实很慢.如果我有一个包含很多项目的长列表,那真的需要花费太多时间.所以我的问题是,是否有一个解决方案,每次都有效并且速度快?
我在我的Symfony应用程序中使用FOSUserBundle非常棒.他们在单独的模板中有登录和注册表单.我希望在一个模板中将它们彼此相邻显示.
因此,我创建app/Resources/FOSUserBundle/Security/login.html.twig
并app/Resources/FOSUserBundle/Registration/register.html.twig
覆盖两个模板.在login.html.twig
我调用寄存器控制器来呈现其模板.
应用程序/资源/ FOSUserBundle /安全/ login.html.twig:
{% extends "FOSUserBundle::layout.html.twig" %}
{% trans_default_domain 'FOSUserBundle' %}
{% block fos_user_content %}
{% if error %}
<div>{{ error|trans }}</div>
{% endif %}
<form action="{{ path("fos_user_security_check") }}" method="post">
<input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />
<input type="text" id="username" name="_username" value="{{ last_username }}" placeholder="{{ 'security.login.username'|trans }}" required="required" />
<input type="password" id="password" name="_password" placeholder="{{ 'security.login.password'|trans }}" required="required" />
<input type="checkbox" id="remember_me" name="_remember_me" value="on" />
<label for="remember_me">{{ 'security.login.remember_me'|trans }}</label>
<input type="submit" id="_submit" …
Run Code Online (Sandbox Code Playgroud) 我有一个带有自定义单元格的UITableView.此自定义单元格看起来像样式为"细节左侧"的正常单元格.但我的自定义单元格有一个详细信息标签和一个文本字段,以允许用户编辑文本.我有一个保存按钮,我想保存用户输入的所有数据.我使用本教程编写了自定义单元格:http://agilewarrior.wordpress.com/2012/05/19/how-to-add-a-custom-uitableviewcell-to-a-xib-file-objective-c/ #评论- 4883
为了获取用户数据,我将文本字段的委托设置为表视图控制器(self)并实现了textFieldDidEndEditing:方法.在这个方法中,我要求文本字段的父视图(= cell)并请求该单元格的indexPath.问题是,无论我编辑什么单元格,我总是为indexPath.row得到0.我究竟做错了什么?
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:[CustomCell reuseIdentifier] forIndexPath:indexPath];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
cell = self.customCell;
self.customCell = nil;
}
cell.label.text = @"Some label text";
cell.editField.delegate = self;
cell.accessoryType = UITableViewCellAccessoryNone;
return cell;
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
CustomCell *cell = (CustomCell *) textField.superview;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
NSLog(@"the section is %d and row is %d", …
Run Code Online (Sandbox Code Playgroud) 我使用Select2制作标签框.我添加了以下HTML代码:
<select id="tags" multiple="">
<option value="tag_1">Tag1</option>
<option value="tag_2">Tag2</option>
<option value="tag_3">Tag3</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我用这个JS:
$(document).ready(function() {
$("#tags").select2({
placeholder: "Select tag",
allowClear: true,
minimumInputLength: 2,
maximumSelectionSize: 1,
});
});
Run Code Online (Sandbox Code Playgroud)
问题是:文本框在首次加载时具有正常宽度.插入标签后,它将正确显示.但是,如果我点击退格键或点击标签的x来删除它,文本框就会缩小到5px左右.我究竟做错了什么?我也使用twitter bootstrap,有一些依赖吗?
使用 select2 jQuery PlugIn 我创建了一个标签框。因此我使用了以下 html 表单代码:
<form action="someAction" method="post">
<fieldset>
<select id="tags" multiple="" name="tags">
<option value="tag1">val1</option>
<option value="tag2">val2</option>
<option value="tag3">val3</option>
</select>
<button type="submit" class="btn">Submit</button>
</fieldset>
</form>
Run Code Online (Sandbox Code Playgroud)
Select2 从中生成以下字段:
<input type="text" class="select2-input" autocomplete="off" id="s2id_autogen1" style="width: 10px;">
Run Code Online (Sandbox Code Playgroud)
问题name
在于缺少该属性。$_POST
如果没有name
属性,如何从 PHP中的变量中获取输入字段的数据/文本?我该如何管理?
设置JS如下:
$(document).ready(function() {
$("#tags").select2({
placeholder: "Insert tag",
allowClear: true,
minimumInputLength: 2,
maximumSelectionSize: 1,
minimumWidth: 200
});
Run Code Online (Sandbox Code Playgroud)
});
我使用 Selenium 2 和 Grid 中的 RemoteWebDriver 将测试划分到多个虚拟机上。假设我有两台 Linux 机器,在测试中我指定了在 Linux 机器上运行的功能,但我无法确定正在使用这两台机器中的哪一台。有什么办法可以弄清楚吗?像 driver.getServerIp() 或者其他什么?原因是,在我的 Selenium 测试代码中,我想在运行测试的 Linux 机器的控制台上启动 bash 脚本。因此我必须知道测试在哪台机器上运行。
多谢你们!
对于Magento Backend,我创建了一个Varien_Form来显示.
class MyNamespace_MyModule_Block_Adminhtml_MyModule_Edit_Tabs_Form
extends Mage_Adminhtml_Block_Widget_Form {
protected function _prepareForm()
{
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('my_form', array('legend'=>'ABC'));
$fieldset->addField('data', 'text',
array(
'label' => 'My Textfield',
'name' => 'myTextField'
));
return parent::_prepareForm();
}
}
Run Code Online (Sandbox Code Playgroud)
我现在的问题是,哪些形式的领域是可能的?你看到函数addField()在哪里说'text'?我听说过'复选框'和'隐藏'.但是,是否有所有可能字段的列表?像标签或更多线条的文本框等.非常感谢!
我想在Mac OS 10.7上创建VirtualHosts,因此我编辑了/etc/apache2/httpd.conf.我取消注释"Include /private/etc/apache2/extra/httpd-vhosts.conf"这一行以包含虚拟主机.在文件/private/etc/apache2/extra/httpd-vhosts.conf中,我写了以下内容:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/var/www"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/someFolder"
ServerName myApplication.dev
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/someOhterFolder"
ServerName myApplication2.dev
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
我删除了两个示例虚拟主机.在我的/ etc/hosts文件中,我添加了以下内容:
127.0.0.1 myApplication.dev
127.0.0.1 myApplication2.dev
Run Code Online (Sandbox Code Playgroud)
我重新启动了我的Apache并在浏览器中键入了myApplication.dev和myApplication2.dev,但是我收到错误"找不到服务器",它在浏览器中生成了www.myApplication.dev(对于myApplication2.dev也是如此).
我忘了要配置的东西吗?我在httpd.conf中激活了PHP,也安装了mysql,但我认为这与虚拟主机无关.谢谢你的帮助!
我想解析常见的apache访问日志文件,这是:
::1 - - [02/Mar/2014:15:36:43 +0100] "GET /index.php HTTP/1.1" 200 3133
Run Code Online (Sandbox Code Playgroud)
这是我的过滤器部分:
grok {
match => ["message", "%{COMMONAPACHELOG}"]
}
date {
match => ["timestamp", "dd/MMM/yyyy:HH:mm:ss Z"]
}
Run Code Online (Sandbox Code Playgroud)
所有字段都被识别,但不是时间戳.控制台上的输出如下:
Failed parsing date from field {:field=>"timestamp", :value=>"02/Mar/2014:15:36:43 +0100", :exception=>java.lang.IllegalArgumentException: Invalid format: "02/Mar/2014:15:36:43 +0100" is malformed at "Mar/2014:15:36:43 +0100", :level=>:warn}
Run Code Online (Sandbox Code Playgroud)
我已经检查了日期过滤器的文档.它依赖于DateTimeFormat.
我做错了什么?看不出错误.
我有一个联系表单,我使用FormTypes和validation.yml进行渲染.提交的表单通过POST和AJAX发送到控制器操作.问题是,$form->isValid()
尽管我在表单中输入了正确的数据,但总是返回false.如果我删除validation.yml它仍然返回false.那么表单的验证从何处获取数据?为什么它总是返回假?
这是动作控制器:
public function contactAction()
{
$true = new Response(json_encode(true), 200);
$false = new Response(json_encode(false), 500);
$form = $this->createForm(new ContactType(), new Contact());
$request = $this->getRequest();
if($request->isMethod('POST') && $request->isXmlHttpRequest()){
$form->bind($request);
if($form->isValid()){
// email here
error_log('email worked');
return $true;
}
}
error_log('email not worked');
return $false;
}
Run Code Online (Sandbox Code Playgroud)
validation.yml:
Namespace\XYBundle\Entity\Contact:
properties:
name:
- NotBlank: ~
- Length:
min: 2
max: 20
email:
- NotBlank: ~
- Email: ~
message:
- NotBlank: ~
- Length:
min: 10
max: 10000
Run Code Online (Sandbox Code Playgroud)
这里是ajax调用的jQuery/JS代码:
$.ajax({
type: …
Run Code Online (Sandbox Code Playgroud) 我将最新的tablesorter.js和tablesorter.pager.js包含在我的html文件中.我还包含jQuery 1.9.1.不幸的是,如果我加载页面Firebug说有一个类型错误:
TypeError: $.browser is undefined
Run Code Online (Sandbox Code Playgroud)
我认为$ .browser是jQuery的一部分.那么,1.9.1与寻呼机插件不兼容吗?仅使用tablesorter非常有效,只有寻呼机不起作用.