2017-06-23 6 views
0

無効なファイルタイプをファイルアップロードセクションに追加した後、検証メッセージがツールヒントとして表示されますが、moveToElement()を使用した後でもツールチップを検証できません。ここで ツールヒントを読み取るためのSelenium moveToElement()が機能していません

は、私が目に見えるツールチップを作るために使用されるコードである

`driver.findElement(By.xpath(""//input[@type='file']"").sendKeys(invalidLicenseFileType.txt); 
Actions actions = new Actions(driver); 
actions.moveToElement(//*[contains(@class, 'fieldlabel-content')]).build().perform();` 

ToolTip validation message image

HTMLコード:

<div class="fieldlabel-content"> 
    <label class="fileinput fileinput--invalid"> 
    <div class="fileinput-cell fileinput-cell-input"> 
    <input placeholder="Choose a .license file..." accept=".license" value="" tabindex="0" type="file"> 
    <div class="fileinput-description"> 
    File: 
    <span class="fileinput-description-file"> 
    <span class="icon fa fa-file-text-o"></span> 
    invalidLicenseFileType.txt 
    </span> 
    </div> 
    </div> 
    <div class = "popup popup--theme-error popup--position-top popup--hover" style="top: 131px; left: 399px;">Validation message for uploading invalid file type.</div> 
    </label> 
+0

HTMLを表示できますか? – Buaban

+0

@Buaban質問にHTMLを追加しました – SKV

+0

アクションの前にエラーメッセージやその他のJavaコードを教えてください。 – Buaban

答えて

0

try 
{ 
    String mouseOverScript = "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseover',true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseover');}"; 
    ((JavascriptExecutor) driver).executeScript(mouseOverScript,uploadFileInputFieldWebElement); 
    Thread.sleep(1000); 
    invalidLicenseFileTypeMessag = (String)((JavascriptExecutor)driver).executeScript("return arguments[0].innerHTML;",tooltipWebElement); 


} catch (Exception e) { 
    exception message; 

} 
0

私は問題はアクションがマウスを移動しようとしていることを前提としていその要素はまだ表示されていません。 は、私はこの問題を解決するには、2つの提案を持っている

driver.findElement(By.xpath("//input[@type='file']").sendKeys("invalidLicenseFileType.txt"); 
WebDriverWait wait = new WebDriverWait(driver, 10); 
WebElement element = wait.until(ExpectedConditions. presenceOfElementLocated(By.cssSelector(".popup--theme-error"))); 
Actions actions = new Actions(driver); 
actions.moveToElement("//*[contains(@class, 'fileinput-description-file')]").perform(); 
+0

それは私にとってはうまくいかなかったBuaban – SKV

+0

@SujaiKrishnaそれではエラーは何ですか? – Buaban

+0

要素に対してmouseover関数を実行することができません。 – SKV

1

以下のコードを試すことができます:最後の行で

First : Using JavaScript

WebElement element = driver.findElement(By.xpath("value of xpath")).sendKeys(invalidLicenseFileType.txt); 
JavascriptExecutor js = (JavascriptExecutor) driver; 
js.executeScript("arguments[0].onmouseover()", element); 

を、elementの代わりに、あなたが与えることができますxpath of your WebElementをホバーします。

Second : Using Actions

アクションクラスにmoveToElementの代わりにclickAndHoldを使用してみてください。

WebElement element = driver.findElement(By.xpath("value of xpath")).sendKeys(invalidLicenseFileType.txt); 
Actions actions = new Actions(driver); 
actions.clickAndHold(//*[contains(@class, 'fieldlabel-content')]).build().perform(); 
+0

私は要素をフォーカスすることができず、そのために隠し要素からツールヒントテキストを取得することができないというオプションを試しました – SKV

+0

OK、フレームの変更やHTMLのページ変更を確認してください –

+0

フレームがありません私たちがファイルを入力するときにページの変更が行われていて、ファイルのタイプがすぐに無効である場合は、検証メッセージをツールチップとして取得します。ツールチップのdivは、入力ファイルにマウスを重ねるまで隠されています。 – SKV

0

コードに間違いがあります。

コード:私の問題を修正する次のコードのヘルプを実装

driver.findElement(By.xpath("//input[@type='file']")).sendKeys("invalidLicenseFileType.txt"); 
 
Actions actions = new Actions(driver); 
 
WebElement element = driver.findElement(By.xpath("//*[contains(@class,'fieldlabel-content')]")); 
 
actions.moveToElement(element).build().perform(); 
 
String toolTipText = driver.findElement(By.xpath("//div[contains(@class,'popup popup--theme-error')]")).getText(); 
 
System.out.println("Tool tip text present :- " + toolTipText); 
 

 
// Compare tool tip text 
 
Assert.assertEquals("Validation message for uploading invalid file type.", toolTipText);

+0

私は自分のプロジェクトで提供したのとまったく同じコードを使用しています。なんらかの理由で、moveToElement()関数が動作していないため、テスト中に隠れ要素が見つからないため、ツールヒントテキストが取得されません。 – SKV

+0

私が提供したコードをそのままコピーして、もう一度試しましたか?それは動作するはずです。私はあなたが提供したコードでいくつかの間違いを見ることができます。いくつかの構文上の問題。 – Monika

+0

はい、私はあなたが提供したものと全く同じコードを使用していますが、2つの異なる方法で使用しています。方法1はファイルを送信するためのもので、方法2ではmoveToElementを実行して、ツールチップのテキストを取得しています。 – SKV

関連する問題