I have the code which I am trying to run in Selenium webdriver. It is a button but I can't select it with java code. Can you please help me which is true ?
<mat-list-item _ngcontent-c7="" class="menu-item mat-list-item ng-star-inserted" id="kisiler"><div class="mat-list-item-content"><div class="mat-list-item-ripple mat-ripple" mat-ripple=""></div><div class="mat-list-text"></div>
<!----><mat-icon _ngcontent-c7="" class="mat-icon material-icons ng-star-inserted" role="img" aria-hidden="true">group</mat-icon>
<!---->
<!----><mat-label _ngcontent-c7="" class="ng-star-inserted">Kişiler</mat-label>
</div></mat-list-item>
My code is:
driver.findElement(By.id("[#id='kisiler']")).click();
To click on the element with text as Kisiler you need to induce WebDriverWait for the element to be clickable and you can use the following solution:
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//mat-list-item[#class='menu-item mat-list-item ng-star-inserted' and #id='kisiler']//mat-label[#class='ng-star-inserted']"))).click();
Related
I am trying to click a button that has these details when I F12
<a data-codecept="searchGo" id="9" class="a-button a-button--white clearfix block showall" suggestrow"="" alt="/s/lundhags/?searchparam=lundhags" onmouseover="suggest.handleMouseOver(9);" onmouseout="suggest.handleMouseOut(9)" onclick="suggest.handleSubmit();" xpath="1">Show all results for 'lundhags'<span class="a-icon a-button__icon a-button__icon--double-arrow"></span></a>
I have copied xpath and I had a code like this=>
I.click('//*[#id="9"]');
and I got this error
Clickable //*[#id="9"] was not found by text|CSS|XPath
What am I doing wrong?
It works now! I used the specific Identifier
I.click('[data-codecept="searchGo"]');
frame html code:
<iframe title="frame report" class="ReportViewer__iframe" src="/yesyyy.aspx?reportId=145&ts=1550681978158&bgcolor=#f8f9fb" width="100%" height="100%"></iframe>
script fails both for title and class name locators -- 'ERROR webdriver: Request failed due to Error: no such frame'
Use the following code.
driver.switchTo().defaultContent();
WebElement frameXpath = driver.findElement(By.xpath("//iframe[#title='frame report']"));
driver.switchTo().frame(frameXpath);
Got the solution, pass the object of the iframe with available locators (title or css class)
browser.switchtoframe($('.report__iframe'))
HTML Code:
iframe id="ifr" name="demo" src="demo.html" height="200" width="300">
Switch statement:
browser.switchToFrame($("//iframe[#src='demo.html']"))
For more info read here: https://chercher.tech/webdriverio/iframes
I have an element like this:
<a class="btn">Select</a>
How do I click this using selenium webdriver?
To click() on the link with text as Select you can use either of the following options :
Python link_text :
driver.find_element_by_link_text("Select").click()
Python xpath :
driver.find_element_by_xpath("//a[#class='btn' and contains(.,'Select')]").click()
Java linkText :
driver.findElement(By.linkText("Select")).click();
Java xpath :
driver.findElement(By.xpath("//a[#class='btn' and contains(.,'Select')]")).click();
My application requires to test favorite feature for any product.Products List & UI
When a user click on the heart icon shown in the snippet, it will add that product into Favorites list. I would like to know about the Capybara/Cucumber method to click on the heart icon.
I have tried using XPATH but it seems not working. The code that I tried is as follow.
When(/^I click on the favourite icon on the first product$/) do
find(:xpath,'/html/body/div[1]/div[2]/div/div/div/span/div/div/div/div[3]/div[1]/span[1]/div/div/div/div/div[4]/div[2]/div/favorite/a').click
end
I have also tried following capybara method using XPATH. It is also not working.
When(/^I click on the favourite icon on the first product$/) do
find(:xpath,'//a[contains(., "#heart")]).click
end
Also, I tried following code which is throwing out an error.
When(/^I click on the favourite icon on the first product$/) do
within("div.search-results-wrapper") do
find(first('a.ng-scope')).trigger(:mouseover)
end
end
Error:
The given selector #<Capybara::Node::Element:0x007fd18d841690> is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: An invalid or illegal selector was specified (Selenium::WebDriver::Error::InvalidSelectorError)
The HTML code for the Favorite icon is as follow:
<favorite product="result" ng-if="!ui.showIpsaProductCell()" class="product-action ng-scope ng-isolate-scope"><a ng-mousedown="product.favoriting = true" ng-mouseenter="product.showList = true" active="::product.favoriting" ng-click="toggle(true)" class="ng-scope active">
<i ng-class="::{
'icon-heart-filled':
product.hasFavorite || !showCount || newProductPage,
'icon-heart-outline':
!product.hasFavorite && showCount && !newProductPage
}" class="heart icon-heart-filled"></i>
<!-- ngIf: ::showCount --><span class="count ng-scope" ng-if="::showCount">
1
</span><!-- end ngIf: ::showCount -->
<!-- ngIf: ::addToList && product.hasFavorite --><div component="add-to-list" ng-if="::addToList && product.hasFavorite" class="ng-scope">
<!-- ngInclude: '/modules/components/add-to-list/add-to-list.tpl.html' --><span ng-include="'/modules/components/add-to-list/add-to-list.tpl.html'" ng-controller="AddToListCtrl" class="ng-scope"><div ng-mouseleave="product.showList = false" class="add-to-list-desktop ng-scope">
<!-- ngIf: product.showList -->
<!-- ngIf: product.showListMenu && product.showList -->
</div>
</span></div><!-- end ngIf: ::addToList && product.hasFavorite -->
</a></favorite>
Since you have multiple "favourite" icons you would need to find your icon within a given parent container, not being able to see the full html page it would go something like:
within(".myParentContainer") do
find(".icon-heart-filled").click
end
Could anyone suggest how I can locate the element "ToBeSelected" that has the below html code:
<div id="Locate-17-tab-info" class="tab active" data-tab-name="tobeselected"> ToBeSelected </div>
The XPath
driver.findElement(By.xpath("input[contains(#id, '-tab-info')]")).click();
I did not have success with finding by XPath - starts-with and ends-with.
You May try
driver.findElement(By.xpath(//input[contains(#id,'Locate') and text()='ToBeSelected'])).click();