I have a submit button with text and I want to check for both.
i.e. the actual page has:
<input class="button" type="submit" value="Continue" tabindex="3"
name="nav[save]"></input>`
So I've tried
it "I can see the Continue button" do
expect(page.find('input[type="submit"]').find('input[value="Continue"]')).to be
end
but I get
Unable to find css "input[value=\"Continue\"]"
and
expect(page.find('input[type="submit"]')).
to have_selector('input[value="Continue"]')
but I get
expected to find css "input[value=\"Continue\"]" but there were no matches
If you want to check for both you can do it in single css selector like
input[type=\"submit\"][value=\"Continue\"]
Here's one solution that works with your view:
expect(find('.button').value).to eq 'Continue'
In the console:
[1] pry(#<Cucumber::Rails::World>)> expect(find('.button').value).to eq 'Continue'
=> true
Related
I have 2 strange problems. I have a large form with lots of input fields. That works fine. I want to add a slide toggle at the bottom which changes a variable that will affect styles on the whole form.
My first problem is that the variable will not display until the slide toggle is clicked.
HTML
<mat-slide-toggle [(ngModel)]="ifPrint" name="ifPrint" id="ifPrint" ></mat-slide-toggle>
<div>
{{ifPrint}}
</div>
COMPONENT
export class PrintReviewDetailsComponent implements OnInit {
ifPrint = true;
}
the ifPrint variable is blank on page load
The second problem is
when the slide toggle is clicked the div containing the variable shows as true but when I click the toggle to the off position the ifPrint variable stays as true and does not change.
I have created a blitz and it is working fine there with the same code so I am unsure as why I am having these issues on my page.
The console says:
Error: No value accessor for form control with name: 'ifPrint'
EDIT: I updated the stackblitz to include the html of the form and now it is not working.
Your updated stackblitz couldn't recreate the issue which you shared... But from your question, the following 2 issues are addressed for a form and styling is also done:
the toggle value was not displayed by-default until the toggle was clicked
the toggle value didn't change when you toggled it
the style is now being updated based on the toggle value
relevant TS:
model:any;
constructor(){
this.model = {name: '' , age: null, ifPrint: false};
}
relevant HTML:
<form (ngSubmit)="formSubmit()" #demoForm="ngForm" >
<div [ngClass]="model.ifPrint === true ? 'trueClass' : 'falseClass'">
<input type="text" placeholder="Enter Name" #name="ngModel" [(ngModel)]="model.name" name="name" />
<br/>
<input type="number" placeholder="Enter Age" #age="ngModel" [(ngModel)]="model.age" name="age" /> <br/>
<mat-slide-toggle #ifPrint #age="ngModel" [(ngModel)]="model.ifPrint" name="ifPrint"></mat-slide-toggle> {{model.ifPrint}} <br/>
</div>
<button type="submit"> Submit </button>
</form>
check a minimal, working demo here for what you're trying... hope it helps...
I removed everything in your template except the mat-slide-toggle and it works as expected.
I believe the issue is because your html template is referencing methods or properties that your component does not have, or trying to access a property of null or undefined somewhere is causing the issue.
Check your console for the errors and if you fix those up, the slide toggle should work as expected.
I am writing a selenium test with capybara and trying to fill out a pop-up box. I am not able to fill in the name of the element using fill_in method in capybara. This works perfectly fine with other forms in other pages but not on this one.
Here is my test code:
describe "Jobs" do
before do
login(users(:admin))
end
it "creates a job on a workspace" do
visit('#/workspaces')
click_button "Create Workspace"
within_modal do
fill_in 'name', :with => "testing-jobs"
click_button "Create Workspace"
end
click_link "Dismiss the workspace quick start guide"
page.should have_content('All Activity')
Workspace.find_by_name("testing-jobs").should_not be_nil
click_link "Jobs"
click_button "Create"
within('#facebox') do
find(".name").click
fill_in '. name', :with => "real job"
choose "onDemand"
click_button "Create"
end
page.should have_content "real job"
end
end
The first fill_in with respect to workspace works really fine but when I get to the jobs it just screws up.
Here is the actual dev code from firebug:
<div id="facebox" class="dialog_facebox" style="top: 30px; left: 424.5px;">
<div class="popup" style="max-height: 626px;">
<div class="content">
<div class="configure_job_dialog dialog">
<div class="dialog_header">
<div class="errors"></div>
<div class="dialog_content" data-template="configure_job_dialog">
<form action="#">
<label class="required">Name</label>
<input class="name" type="text" value="">
I am using the name class in the fill_in method but capybara is not catching it. I tried to debug a little more to see why my workspace gets created but not the job. The workspace code is as follows.
<input type="text" maxlength="256" tabindex="1" placeholder="Name this workspace" name="name">
Any help is highly appreciated.
Problem
Based on the html given, you will not be able to use the fill_in method. The reasons are that:
The fill_in method locates elements based on their id attribute, name attribute or label text. It does not support locating elements by a CSS-selector, which .name is.
The element does not have an id or name attribute and therefore cannot be used by fill_in. As well, the label is not directly associated with the input via for and id attributes. I believe fill_in only checks explicit labels (rather than implicit labels).
Note that the fill_in works for the workspace because that input has a name attribute specified.
Solution
The ideal solution would be to update the input to have an id attribute, name attribute or explicit label. However, if that is not possible or if you need to use the CSS-selector, you can find the element and then set the value:
find('.name').set("real job")
I want to create a html page, where the data given in the submit button should automatically?
go the other buttons ..for example :
If i enter america in the submit button ;
below that i want a google button where the value "America" should go directly to the google button so when the user clicks google button the search result for america should be displayed.
Ex : https://www.google.co.in/?gws_rd=cr&ei=vTtxUpqDGM3arAf-rYHoAw#q=america ;
The submit button text should be placed after the "=" in the google link
Your question is unclear, but i guess this is what you want ...
<form action="http://www.google.com/search" method="get">
Google Search: <input type="text" name="q" />
<input type="submit" value="Search" />
</form>
I want to have a top menu with New, Save, Cancel buttons and below, 3 different entry forms, similar to a "desktop application". When form1 is filled up, Save button would submit the form. Also, if form2 or form3 are filled up, the same Save button can submit the form, taking into account that is in a different form.
Is it possible to do this, a submit button outside form tags ?
If not, any suggestion how to fake submit?
Thanks for your help
You just have to trigger the submit event with .submit in jQuery by example.
Here is the doc : http://api.jquery.com/submit/
Instead of an <input type="submit"> button or jQuery call you could use the new HTML5 <button> element and its form attribute to specify which form(s) the button belongs to. Then just set its formaction attribute to the required destination. Documentation
Example:
<form id="form1">
...
</form>
<form id="form2">
...
</form>
<form id="form3">
...
</form>
<button form="form1 form2 form3" formaction="processForm.php" formmethod="POST">
Submit
</button>
You can use
$("#formId").submit(function() { /*your stuff*/ });
How to get the attribute of Title in the input element
<input type="image" title="Previous Page">
<input type="image" title="First Page">
<input type="image" title="Next Page">
<input type="image" title="Last Page">
What have you tried? Typically something like the following should work:
WebElement element = driver.findElement(By.tagName("input"));
String title = element.getAttribute("title");
The answer provided by Jim Evans is the correct one imo, but for a more specific one i'd advise something like below. Remeber that copy-pasta might not work and you need to change something to be able to work on your full HTML.
List<WebElement> elements = driver.findElements(By.tagName("input"));
for (WebElement element : elements) {
if (element.getAttribute("type").equals("image")) {
System.out.println(element.getAttribute("title"));
}
}
The above code will loop for all the in your webpage that are from type="image" and print on the console the "title" attribute of each one of those.
Still thing you should vote Jim's answer as the correct one though.
First, you need to identify the input element from which you want to get the value of the attribute title .
Then something like the following must work.
element.getAttribute("title");
Its very simple and work for as well.
String title = driver.getTitle();