Does anyone have proper practical step definition for this?
And I click the following likes:
| a |
| b |
Expecting proper step definition to click those elements from datatable
Related
I created my own customized xpath for the following steps to LinkedIn:
www.linkedin.com - Launch the URL
Sign in
View Profile
Click on Jobs
Type in QA Lead
Click on Date Posted
Select within 24hrs
Click on Apply <------ Here where I am not able to click on this button.
Xpath:
driver.findElement(By.xpath("button[#class='facet-collection-list__cancel-button mr2 artdeco-button artdeco-button--muted artdeco-button--2 artdeco-button--tertiary ember-view']//span[text()='Cancel']/parent::button/following-sibling::button//span[#class='artdeco-button__text']")).click();
enter image description here
You need to identify the expanded section first, then some unique attribute of the button, example:
Xpath: //form[#aria-expanded='true']//button[#data-control-name='filter_pill_apply']
css: form[aria-expanded=true] button[class*=apply]
I was able to figure it out. I modified the xpath accordingly and it worked:
driver.findElement(By.xpath("//*[#data-control-name='filter_pill_cancel' and #class='facet-collection-list__cancel-button mr2 artdeco-button artdeco-button--muted artdeco-button--2 artdeco-button--tertiary ember-view']//span[#class='artdeco-button__text' and text()='Cancel']/parent::button/following-sibling::button//span[text()='Apply']")).click();
<md-nav-list>
<md-list-item *ngFor="let distributionGroup of distributionGroupIndexes$ | async;"
(click)=selectDistributionGroup(distributionGroup.id)>
<span>{{distributionGroup.name}}</span>
</md-list-item>
</md-nav-list>
In the example above I would like to be able to specify the initially selected md-list-item. I cant seem to find a way of doing this.
The list is being populated asychronously (notice the | async) but I dont think that is the source of my trouble...
I have found references to md-selected-item for other material elements, so optimistically attempted adding
md-selected-item="distributionGroupIndexes$[0] | async" to md-nav-list, but no joy.
Any hints as to how this should be done would be greatly appreciated.
You may of solved this by now bu this could help someone else, I binded the selection to a data model from the view to the component.ts.
<md-list-item *ngFor="let distributionGroup of distributionGroupIndexes$ | async;"
(click)=selectDistributionGroup(distributionGroup.id)>
add this within the tag:
[(ngModel)="distributionGroup.id"]
then give it default value in the component, the view will load with this value selected.
The website which I am trying to automate is - http://www.lufthansa.com/online/portal/lh/ua/homepage
In the Search Flights form, there is a dropdown for selecting the number of passengers. I am handling it using the Select class. My code is as shown below -
WebElement dropdown = driver.findElement(By.xpath("//*#id='ns_7_CO19VHUC6N5PC0ACV6A7BG2I12_fmAdults']/tbody/tr/td[1]"));
Thread.sleep(3000L);
Select selectbox = new Select(dropdown);
Thread.sleep(3000L);
selectbox.selectByIndex(2);
I get the error as -
Exception in thread "main" org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "td"**.
Now if I change my code as below it works absolutely fine.
driver.findElement(By.xpath("//*#id='ns_7_CO19VHUC6N5PC0ACV6A7BG2I12_fmAdults']/tbody/tr/td[1]")).click();
Thread.sleep(3000L);
driver.findElement(By.xpath("//*[#id='dijit_MenuItem_2_text']")).click();
I would like to handle this by using the fundamentals of Select, and not by the above mentioned method. Plese help. Let me know what am I missing here
I have a cucumber feature file which looks like below,
Given I am logged in to the console
When I navigate to the "href1" page
When I navigate to the "href2" page
When I navigate to the "href3" page
When I navigate to the "href4" page
Instead on writing the when command 4 times I want to know if I can somehow pass the value of the href and call it in the when statement.
I have a step definition which looks like this :
When(/^I navigate to the "(.*)" page$/) do |navigation_link|
#browser.link(:href => navigation_link).when_present.click
end
Let me know if you need more information.
Multiple options to do it:
a) If you need to test that you can navigate to each of the pages independtly, you can use a Scenario Outline like:
Scenario Outline: Test navigation
Given I am logged in to the console
When I navigate to the "<href>" page
Examples:
|href |
|<actual_url1>|
|.... |
|<actual_url4>|
In this case, your step doesn't need to be modified, and should work as is.
b) If you need to navigate to the pages in a dependent manner, i.e., reaching page 4 requires you to follow through page1 -> page2 ->... page X -> page 4, you can use a table like:
Scenario: Test navigation
Given I am logged in to the console
When I navigate through the following pages:
|<actual_url1>|
|.... |
|<actual_url4>|
And then in your step definition:
When(/^i navigate through the following pages:$/) do |table|
table.raw.each do |navigation_link|
#browser.link(:href => navigation_link.join).when_present.click
end
end
(Read more on tables & outlines here: http://cukes.info/step-definitions.html)
Though, I wouldn't suggest using either of them if you just want to check that you can navigate to page4. I'd rather create the step to only navigate to page 4, and within that step's definition-> take the url_paths in variables (much better to have in a separate paths file and load from there)-> navigate to other pre-requisite pages-> Navigate to the final page.
This way you would only describe the behaviour and not literal navigation points.
I have a web page with a grid, and some columns have a link in the column header that will sort the values by that column [by round-tripping to the server].
I want to write a single Watir test that will identify those sorting links and click each one in succession. This is a smoke test that ensures there are no runtime exceptions resulting from the sort expression.
My question is, what is the best way to (1) identify these links, and (2) click each one in succession? This is what I have so far:
$ie.table(:id, "myGrid").body(:index, 1).each do | row |
row.each do | cell |
## todo: figure out if this contains a sort link
## todo: click the link now, or save a reference for later?
end
end
I think it won't be possible to click each link inside the loop since clicking a link will trigger a page load and I believe this invalidates the other Watir Link Elements.
So, what I suggest is that you take the IDs of the links and then loop over each other doing the clicks.
For instance, I would add an specific class to those sorting links and a meaningful id too.
Something along the lines of:
<a id='sortby-name' class='sorting' href='...'>Name</a>
Then you can pick them with this:
$ie.table(:id, "myGrid").body(:index, 1).each do | row |
# pick sorting links' ids
sorting_link_ids = row.links.select{|x| x.class_name == "sorting"}.map{|x| x.id}
end
And then, you do your clicking like this:
sorting_link_ids.each do |link_id|
$ie.table(:id, "myGrid").body(:index, 1).link(:id, link_id).click
end
Hope that helps!