Part of the class name is loaded dynamically ( ico-partly-cloudy)..I am trying to get this part only form
source html
<div data-ng-class="'icon-' + day.icon + '-' + theme" class="forecast-icon ico-partly-cloudy" xpath="1"></div>
by using:
response.xpath('//html[1]/body[1]/div[1]/div[1]/div[3]/div[2]/div[1]/div[1]/#class=forcast-icon').extract()
I was looking to get the remaining part of the class attribute which changes dynamically. The above certainly does not do it
This will do it:
response.xpath('//html[1]/body[1]/div[1]/div[1]/div[3]/div[2]/div[1]/div[1]/#class').extract_first().split('forecast-icon ')[1]
For a simpler option using just xpath, change your xpath expression to:
//div[#data-ng-class][contains(#class,"forecast-icon")]/substring-after(#class,"forecast-icon ")
thing you can do it with css like this
response.css('.forecast-icon.ico-partly-cloudy').get()
now i dont know how you get hte selection
Related
I need to find a button element using XPath. The problem is, the button has no unique identifier like Id or name, but is located inside another element which has a unique class (i.e. a class that no other element on page uses). I know how to get to that element and identify it by class but I don't know how to access the button inside that element.
.//mat-header-cell[#class='mat-header-cell cdk-column-delete mat-column-delete ng-star-inserted']
Any suggestions?
SOLUTION I FOUND:
Just added '//button' to the end of xpath and it works now!
.//mat-header-cell[#class='mat-header-cell cdk-column-delete mat-column-delete ng-star-inserted']//button
We have used angular custom directive to generate a custom html tag called .The corresponding style sheet file for this tag is student.scss and its content is
student-result {/* Sonarqube is reporting critical issue at this line saying
"Remove the usage of the unknown "student-result" type selector" */
.student-result-top {
position :absolute;
height :300px;
}
}
Can anybody suggest any way to resolve the issue or any plugin which will make sonarqube to recognize these custom HTML tags?
Geo j's approach of using a class selector instead of an element selector is good. Instead of editing every html source file to add the class, you can use #HostBinding to give every instance of the component the same class by default:
#HostBinding('class.student-result') hasStudentResultClass = true;
Instead of using the angular selector directly inside your scss file give an id or class to it and apply required style.
<student-result class="student-result"></student-result>
Now in your scss access the same selector as .student-result instead of student-result. This might help I believe.
Does anyone know how to set a value to span tag using capybara?
I tried using element.set or element.send_keys, they only selected the targeted element without modifing the previous value.
<div data-offset-key="bbpvo-0-0" class="_1mf _1mj"><span data-offset-key="bbpvo-0-0"><span data-text="true">aa</span></span></div>
HTML snippet is above, I want to set aa to bb.
Capybara is designed to emulate a user - A user can't edit a span unless there's some sort of javascript widget attached to it. If you have a JS widget attached to the span you would need to perform whatever actions a user would do in order to edit the span. So you say the user has to click on the span and then type on the span - if that is so then you could try something like
span = find('span[data-text="true"]')
span.click
span.send_keys("new content", :enter) # if enter is needed to end the editing
which may work - although I'm going to guess the element actually gets replaced with an input or something after it's clicked on, in which case you need to figure out what those elements are (using the browsers inspector) and then find and use send_keys or set on that element instead
To set text in span value,jquery can be used with capybara as shown below:
page.execute_script("$("<span css selector>").text("testing")");
or
page.execute_script("$("<span css selector>").html("testing <b>1 2 3</b>")");
I am new to automation (Cucumber), and has very less idea of coding. I am looking for the script through which I can click on checkbox or radiobutton. Below is the HTML code I am looking at:
<"input class="facetoption" type="checkbox" value="facets.price_range%5B%5D=Rs.+2000+and+Below" autocomplete="off">
And below is the step definition which I tried
Step definition:
Then(/^Select the first Price Range Option$/) do
#browser.checkbox(:value => 'facets.price_range5B%5D=Rs.+2000+and+Below').click
end
The value in your locator doesn't match the value in the <input> tag. Compare the strings, and you'll see they are different.
your HTML: "facets.price_range%5B%5D=Rs.+2000+and+Below"
your code: "facets.price_range5B%5D=Rs.+2000+and+Below"
Update your step definition to the following, and it should work:
Then(/^Select the first Price Range Option$/) do
#browser.checkbox(:value =>'facets.price_range%5B%5D=Rs.+2000+and+Below').click
end
I don't know why you try to find checkbox by value. Better option is to find checkbox by id or class:
find('input#id').click()
If you still like to find checkbox by value please use:
find(:xpath, "input[#value='John']").click()
Use a regex so you can focus on the imporant parts, and ignore the unimporant parts
#browser.checkbox(:value => /2000\+and\+Below/).click
I am trying to select a link/button inside of a form, that is in a div. the way it was made is that there are two links/buttons of the same id, name etc. however they are in different forms, so the code i wanted to use is:
_myTest.Form(Find.ById("PermissionsForm")).Child(Find.ByClass("saveBtn")).Child(Find.ByText("SAVE"));
any help would be appreciated
I think this is what you need:
var button = _myTest.Form("PermissionsForm").Button(Find.ByClass("saveBtn"));
This will lookup the button having the class 'saveBtn' inside the form 'permissionsform' in your browser instance _myTest.
Have a look at this page to decide if you need to have .Button(..) or .Link(...) based on the html tag that is used in your html.
How about building a regex for the element?
Regex could something like this
Regex elementRe = new Regex("id=LnkOk href="http://stackoverflow.com");
Then you can use your code to Click this link. The Click method can be extended to accept Regex if it is not already doing that.
Let me know how this goes or if you need more info.
Cheers,
DM