Reputation: 33
I'm having a hard time getting the correct xpath or locating this element by Selenium. Getting this error:
FAILED: homeLoan("John Smith", "[email protected]", "Australia", "1563", "62365896410", "Home Loan", "Buying", "100000", "50000") org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"name","selector":"FullName"}
My selenium code is:
@Test(dataProvider="homeLoan")
public void homeLoan(String fullname, String email, String countryTypes, String postcode, String phone, String loanType, String loanPurposes, String securityValue, String homeLoanAmount) throws Exception {
// open | https://test-www.loans.com.au/
driver.get("https://test-www.loans.com.au/");
// click | link=contact |
driver.findElement(By.linkText("contact")).click();
// type | name=FullName
**driver.findElement(By.name("FullName")).clear();
driver.findElement(By.name("FullName")).sendKeys(fullname);**
// type | name=Email
driver.findElement(By.name("Email")).clear();
driver.findElement(By.name("Email")).sendKeys(email);
This is the html and I think the element I am trying to look for is in an iFrame:
<body style="overflow:hidden;" onload="iframe_resize();">
<div class="UWP">
<link id="cssLink" type="text/css" rel="stylesheet" data-bind="attr: { href: customStylesheetLocation}" href="/CMSPages/GetResource.ashx?stylesheetname=Referrer_Loans"/>
<!--<div data-bind="template: { name: 'loading' }, visible: IsLoading()"></div>-->
<input id="SessionLandingPageOriginalUrl" name="SessionLandingPageOriginalUrl" value="https://test-www.loans.com.au:443/uwp/callme/?sl=loans&typeid=5&action=hs&f=UWPIFrameCallSingleColumn" type="hidden"/>
<input id="SessionID" name="SessionID" value="yfuywfsdebpmcv0j3i1peylw" type="hidden"/>
<input id="SessionHostServer" name="SessionHostServer" value="TEST-K9-A1" type="hidden"/>
<input id="SessionReferrerUrl" name="SessionReferrerUrl" value="https://test-www.loans.com.au/" type="hidden"/>
<input id="ClientIPAddress" name="ClientIPAddress" value="172.21.0.200" type="hidden"/>
<input id="ClientUserAgent" name="ClientUserAgent" value="Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0" type="hidden"/>
<input id="ClientJavascriptEnabled" data-val="true" data-val-required="The ClientJavascriptEnabled field is required." name="ClientJavascriptEnabled" value="False" type="hidden"/>
<input id="ClientCookiesEnabled" data-val="true" data-val-required="The ClientCookiesEnabled field is required." name="ClientCookiesEnabled" value="False" type="hidden"/>
<div id="container" data-bind="visible: !IsLoading()" style="">
<div class="col-sm-12">
<div class="form-group">
<div data-bind="template: { name: 'commoncontrol', data: CommonControl }">
<div data-bind="visible:ShowCustomerDetails">
<div data-bind="visible:ShowNewCustomerButtons">
<div class="control col-sm-12 valid">
<div class="form-group">
**<input class="form-control inputbox bg-icon-name" placeholder="Full Name*" data-bind="attr: { name: FieldPrefix() + 'FullName' }, value: FullName, enable: ShowCustomerDetails" required="required" name="FullName" type="text"/>**
<div class="field-error">This field is required.</div>
</div>
</div>
<div class="control col-sm-12" style="margin-top:-15px;" data-bind="css: { invalid: ShowNameError() }">
<div class="control col-sm-12 valid">
The html code in bold font is the one I am looking for the xpath.
Any help will do. Thanks in advance.
Upvotes: 2
Views: 5104
Reputation: 150
All you have to do is switch to the frame before you try to locate the elements, like the following:
driver.switchTo().frame("UWPIFrame");
Your code will look like this:
@Test(dataProvider="homeLoan")
public void homeLoan(String fullname, String email, String countryTypes, String postcode, String phone, String loanType, String loanPurposes, String securityValue, String homeLoanAmount) throws Exception {
// open | https://test-www.loans.com.au/
driver.get("https://test-www.loans.com.au/");
// click | link=contact |
driver.findElement(By.linkText("contact")).click();
//Switch to the frame
driver.switchTo().frame("UWPIFrame");
// type | name=FullName
driver.findElement(By.name("FullName")).clear();
driver.findElement(By.name("FullName")).sendKeys(fullname);
// type | name=Email
driver.findElement(By.name("Email")).clear();
driver.findElement(By.name("Email")).sendKeys(email);
But remember, if you try to locate another Element that is not in the iframe you will need to switch back to the default content like this:
driver.switchTo().defaultContent();
Upvotes: 1