2017-11-19 9 views
0

を使用してブートストラップモデルで提示テキストボックスに値を設定することができますが、このテキストボックスが表示されますブートストラップモデルで、それはそれだけで(第二の画像を参照してください。プレースホルダタイプ属性を持っている同上または名前属性、 を持っていません。私はここ数時間、この作業に取り組んでいますが、役に立たないものはありません。は、どのように私は</strong> Firefoxの</strong><strong>に(<em>は、画像</em>、下記を参照してください)webdriverを<strong>セレンを使用して名前の値を設定したいプレースホルダ

私はコードの下にしようとしています:

> WebElement username = driver.findElement(By.xpath("//input[contains(@placeholder,'Name')]")); 

以下はHTMLからいくつかの行です:

<div class="modal welcome__modal is-active"> 
<div class="modal__overlay welcome__modal__overlay" style="background-color: rgba(71, 70, 86, 0.1);"></div> 
<div class="modal__content welcome__modal__content" style="padding: 10px 0px; width: 600px;"> 
    <div style="overflow: auto; width: 100%;"><span style="opacity: 0;">_</span> 
     <div class="welcome__modal__content__wrap" style="display: flex; flex-direction: column;"> 
      <div class="welcome__modal__content__heading"><a class="welcome__modal__content__heading__logo" style="display: flex; align-items: center; margin-top: 1px;"><img src="/5729a135ccb77ae7a0744b6903af9cb8.svg" alt=""><img src="/6e963a3bd5d0e46cfc51abd29cb5e047.svg" alt="" style="margin: 3px 0px 0px 10px;"><h1 class="sr--only">Primedice</h1></a> 
       <h3><span>The most <strong>popular</strong> and <strong>trusted</strong> Bitcoin gambling website.</span></h3> 
      </div> 
      <form class="welcome__modal__content__form" autocomplete="off"><input placeholder="Name" type="text"><button class="btn"><span><!-- react-text: 971 -->Join <!-- /react-text --><strong>3,241,212</strong><!-- react-text: 973 --> players now<!-- /react-text --></span></button></form> 
      <div class="welcome__modal__captcha is--hidden"> 
       <div> 
        <div style="width: 304px; height: 78px;"> 
         <div><iframe src="https://www.google.com/recaptcha/api2/anchor?k=6LeX6AcTAAAAAMwAON0oEyRDoTbusREfJa2vxDMh&amp;co=aHR0cHM6Ly9wcmltZWRpY2UuY29tOjQ0Mw..&amp;hl=en&amp;type=image&amp;v=r20171115120512&amp;theme=light&amp;size=normal&amp;cb=c2gxjjpxcbva" role="presentation" scrolling="no" sandbox="allow-forms allow-popups allow-same-origin allow-scripts allow-top-navigation allow-modals allow-popups-to-escape-sandbox" height="78" frameborder="0" width="304"></iframe></div><textarea id="g-recaptcha-response-1" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px; height: 40px; border: 1px solid #c1c1c1; margin: 10px 25px; padding: 0px; resize: none; display: none; "></textarea></div> 
       </div> 
      </div> 
      <p class="welcome__modal__content__login"><span>Already have an account?</span> 
       <!-- react-text: 978 -->&nbsp; 
       <!-- /react-text --><strong style="cursor: pointer;"><span>Login here</span></strong> 
       <!-- react-text: 981 -->. 
       <!-- /react-text --> 
      </p> 
     </div> 
     <p class="welcome__modal__content__terms"><small><span>By accessing the site I attest that I am at least 18 years old and have read the</span><!-- react-text: 985 -->&nbsp;<!-- /react-text --><span style="text-decoration: underline; font-weight: 600; cursor: pointer;"><span>Terms &amp; Conditions</span></span><!-- react-text: 988 -->.<!-- /react-text --></small></p> 
    </div> 
</div> 

誰かが、私を助けてください。

enter image description here

enter image description here

+0

を起こっていますか?私の答えが役に立つのであれば、答えの近くにチェックを入れてください。上記のコード –

答えて

1

テキストボックスは、ブートストラップモーダルダイアログボックスに表示されていることを述べたように、我々は次のように適切なwaitとの適切xpathを構築する必要があります。

WebDriverWait wait_modal = new WebDriverWait(driver, 10); 
wait_modal.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='modal__content welcome__modal__content']//input[type='text' and @placeholder='Name']"))).sendKeys("debanjan"); 
1

以下の方法を使用してみてください:

まずルート要素を取得し、WebElementオブジェクトにそれを維持。フォーム要素を見つけ、最後に入力要素に値を送信します。

WebElement elem = driver.findElement(By.cssSelector("div.modal__content.welcome__modal__content")); 
//wait until the form is appeared [here apply wait functionality] 
WebElement username = elem.findElement(By.className("welcome__modal__content__form")); 
username = username.findElement(By.cssSelector("input[type='text']")); 
username.clear(); 
username.sendKeys("John dohn"); 
+0

は私のために働いていません。 – Rik

+1

@Rik他のエラーメッセージである –

+1

@Rikの親要素を含む完全なhtml要素を送信できますか? –

1

あなたはそのプレースホルダで要素を見つけることを試みること:

driver.findElement(By.xpath("//input[@placeholder='Name']")) 

が、それはあなたのお役に立てば幸い!

+0

私は以下のコードを試していますが、名前に値を設定していません---- WebElement username = driver.findElement(By.xpath( "// input [@ placeholder = 'Name']")); username.clear(); username.sendKeys( "rikhi.sahu.001"); – Rik

0

このコードで試してみてください。

username = driver.findElement(By.cssSelector(".welcome__modal__content__form>input")); 
username.clear() 
username.sendKeys("Test name.") 

は、それはあなたのお役に立てば幸い!

関連する問題

 関連する問題