我很難得到正確的xpath或Selenium定位這個元素。出現此錯誤:org.openqa.selenium.NoSuchElementException:沒有這樣的元素:無法找到元素
失敗:homeLoan(「John Smith」,「[email protected]」,「Australia」,「1563」,「62365896410」,「房屋貸款」,「購買」,「100000 「,」50000「) org.openqa.selenium.NoSuchElementException:no such element:Unable to locate element:{」method「:」name「,」selector「:」FullName「}
我的硒代碼是:
@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);
這是HTML,我想我試圖尋找該元素是在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">
粗體字的html代碼是我正在尋找xpath的那個。
任何幫助都可以。提前致謝。
我想你可以在'driver.findElement(By.cssSelector(「input [type ='text'] [name ='FullName']」));' – ochi
嘗試'cssSelector',但它仍然無法工作。我也試過這個:driver.findElement(By.cssSelector(「input [name = \」FullName \「]」))。和不工作。任何其他建議? –
你沒有說你在iFrame裏選擇了一些東西;如果是這種情況,請參閱@Renato的答案 - 這就是爲什麼通過切換到iFrame來爲您的代碼提供全部圖片的重要原因[mcve] – ochi