如何使用capybara点击链接.我需要点击毕业链接
<a href="/arts?Occasion=Graduation&top_menu_item_title=+-+Graduation">Graduation</a>
Run Code Online (Sandbox Code Playgroud)
我使用了以下代码.但显示错误消息未定义方法 click
page.find(:link,"Graduation").click
Run Code Online (Sandbox Code Playgroud)
也用过Xpath
page.find(:xpath, "//a[@href='/arts?Occasion=Graduation']").click
Run Code Online (Sandbox Code Playgroud)
它也不起作用
但我的问题是我的页面包含毕业的多个链接.
所以用 page.all(:link,"Graduation")returns Ambiguous match, found 2 elements matching link "Graduation"
我试图将一些数据插入到database.but显示以下错误
Routing Error
No route matches [POST] "/book/create"
Run Code Online (Sandbox Code Playgroud)
表单提交的代码是new.html.erb
<h1>Add new book</h1>
<%= form_tag :action => 'create' %>
<p><label for="book_title">Title</label>:
<%= text_field 'book','title' %></p>
<p><label for="book_price">Price</label>:
<%= text_field 'book','price'%></p>
<p><label for="book_subject">Subject</label>:
<%= text_field 'subject','subject'%></p>
<p><label for="book_description">Description</label><br/>
<%= text_area 'book','description'%></p>
<%= submit_tag "Create"%>
<%= link_to 'Back',{:action=>'list'}%>
Run Code Online (Sandbox Code Playgroud)
routers.rb是
Library::Application.routes.draw do
get "book/list"
get "book/show"
get "book/new"
get "book/create"
get "book/edit"
get "book/update"
get "book/delete"
resources :books, :only => [:new, :create]
match '/books' => 'books#create', :via => :post
Run Code Online (Sandbox Code Playgroud)
这是new.html.erb的html代码
<h1>Add new book</h1>
<form …Run Code Online (Sandbox Code Playgroud) ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1 ruby-on-rails-3.2
在尝试以编程方式删除文件之前,如何检查文件是否已打开?
这样的事情
if (file is open){
// close it first
}
// delete file
Run Code Online (Sandbox Code Playgroud) 我是新手ruby on rails。我想知道如何连接Sql server到 Rails 应用程序。
我正在 Windows 环境中使用 RoR。SQL ServerROR 中有建立连接的链接吗?
我正在尝试在使用以下依赖项时解决依赖项版本冲突。
我面临的最糟糕的情况是项目支持从 1.4 到最新版本的zucchiniapache版本。commons-io不支持1.4以下版本,同时pagerduty-client支持commons-io1.4以下版本。因此,不可能指定支持 zucchini 和 pager-duty 客户端(两者都是第三方库)的此依赖项(依赖项管理)的通用版本。
在这种特殊情况下,我找不到解决此问题的可能方法。任何帮助将不胜感激。
<dependency>
<groupId>com.comcast.zucchini</groupId>
<artifactId>zucchini</artifactId>
<version>[2.2.5,)</version>
</dependency>
<dependency>
<groupId>com.github.dikhan</groupId>
<artifactId>pagerduty-client</artifactId>
<version>3.0.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud) 在以下示例中
以下是说明我的问题的示例代码:
BadDesign.java
public final class BadDesign{
private static int sensitiveData;
public synchronized static void changeDataViaStaticMethod(int a){
//... updating the sensitiveData
sensitiveData = a;
}
public synchronized void changeDataViaNonStaticMethod(int b){
//... updating the sensitiveData
sensitiveData = b;
}
public static void showSensitiveDataStatic(){
System.out.println("Static: " + Thread.currentThread().getName()+ " - " + sensitiveData);
}
public void showSensitiveData(){
System.out.println(Thread.currentThread().getName() + " - " + sensitiveData);
}
public static void main(String[] args){
new Thread(new TestThread11()).start();
new Thread(new TestThread11()).start();
}
}
Run Code Online (Sandbox Code Playgroud)
和TestThread11.java …
这是我用来
删除和重命名目录中的大量文件的代码.
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html; charset=UTF-8");
response.setCharacterEncoding("UTF-8");
RootSipResourceApp.updateRootFile(strDirectorypath, strappID, appNames);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/index.jsp");
dispatcher.forward(request, response);
}
public static void updateRootFile(String directorypath, String appID, String[] appName)
throws IOException {
try {
FileInputStream fin = null;
File[] listOfFiles=fileLists(directorypath);
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
rootFiles = listOfFiles[i].getName();
if (rootFiles.endsWith(".properties") || rootFiles.endsWith(".PROPERTIES")) {
fin = new FileInputStream(directorypath + rootFiles);
properties.load(new InputStreamReader(fin, Charset.forName("UTF-8")));
String getAppName = properties.getProperty("root.label." + …Run Code Online (Sandbox Code Playgroud) 我使用以下代码将XML内容转换为UTF-8,但它们无法正常工作:
1.
InputStream is = new ByteArrayInputStream(strXMLAlert.getBytes("UTF-8"));
Document doc = db.parse(is);
Run Code Online (Sandbox Code Playgroud)
2.
InputSource is = new InputSource(new ByteArrayInputStream(strXMLAlert.getBytes()));
is.setCharacterStream(new StringReader(strXMLAlert));
is.setEncoding("UTF-8");
Document doc = db.parse(is);
Run Code Online (Sandbox Code Playgroud) 我正处于学习Ruby的早期阶段.我真的不知道如何使用在ruby上填充表和数据的现有数据库.每个指南,我在互联网上找到的每篇文章总是使用迁移功能创建一个新文章.
但是在RoR上使用SQL Server中的现有数据库的步骤是什么?
当我更改代码以最大化浏览器窗口时,使用capybara删除浏览器cookie无法正常工作.最初我使用以下代码.如果删除cookie,它可以正常工作
browser = Capybara.current_session.driver.browser
Capybara.default_wait_time = 12
browser.manage.delete_all_cookies
Run Code Online (Sandbox Code Playgroud)
根据我的要求,我需要最大化浏览器窗口.所以我更改了上面的代码如下,并取代错误 browser.manage.delete_all_cookies
browser = Capybara.current_session.driver.browser.manage.window.resize_to(1600, 800)
Capybara.default_wait_time = 12
browser.manage.delete_all_cookies
'startTesting':Undefined method 'manage' for nilClass(noMethodError)
Run Code Online (Sandbox Code Playgroud)