1

Hello im not able to find following dropdown element. Here is HTML code:

<div class="FormDetails"><br>
<ul class="lsn"><br>
<li><br>
<span id="errfileName"></span><br>
</li><br>
<li style="display: block;"><br>
<div class="LeftSection-Form" style="margin-bottom: 15px;"><br>
<div class="FormLabel"><br>
<Community<br>
<span class="FormDetails_required"> Required</span><br>
</div><br>
<div class="FormValue"><br>
<select id="Fact-Communities-LIVE" class="ToolTipPopup Sel1355" tooltip-title=<p>"Community "</p> onkeydown="return preventBackspace(event);" <br>onchange="dropDownValue(this);" name="Fact.Communities.LIVE" emptyoption="-Please select-"><br>
    <option value="TxnyD.PleaseSelect.1.1">-Please select-</option><br>
    <option value="TxnyD.Communities.1.1">UVDB</option><br>
    <option value="TxnyD.Communities.2.1">THQS</option><br>
    <option value="TxnyD.Communities.3.1">Master</option><br>
    <option value="TxnyD.Communities.4.1">Connexio</option><br>
    <option value="TxnyD.Communities.5.1">SL</option><br>
    <option value="TxnyD.Communities.6.1">OG</option><br>
    <option value="TxnyD.Communities.7.1">UT</option><br>
    <option value="TxnyD.Communities.8.1">TR</option><br>
    <option value="TxnyD.Communities.9.1">FGW</option><br>
    <option value="TxnyD.Communities.10.1">E.ON TSMS</option><br>
    <option value="TxnyD.Communities.11.1">Vattenfall TSMS</option><br>
    <option value="TxnyD.Communities.12.1">Delivery1</option><br>
    <option value="TxnyD.Communities.13.1">Test community</option><br>
    <option value="TxnyD.Communities.14.1">Automotive</option><br>
    <option value="TxnyD.Communities.15.1">SHELL SUPPLIER QUALIFICATION SYSTEM</option> <br>
    <option value="TxnyD.Communities.17.1">Nestle</option><br>
    <option value="TxnyD.Communities.18.1">BuildingConfidence</option><br>
</select><br>
</div><br>
</div><br>

i tried following script to find these element:

//driver.findElement(By.xpath(".//*[@id='Fact-Communities-LIVE']")).click();
//driver.findElement(By.xpath(".//*[@id='Fact-Communities-LIVE']/option[16]/text()='SHELL SUPPLIER QUALIFICATION SYSTEM'")).click();

tried these one as well:

//driver.findElement(By.id("Fact-Communities-LIVE")).sendKeys("SHELL SUPPLIER QUALIFICATION SYSTEM");
//Thread.sleep(1000);
//new Select(driver.findElement(By.id("Fact-Communities-LIVE"))).selectByVisibleText("SHELL SUPPLIER QUALIFICATION SYSTEM");

& these one as well

//WebElement dropDown = driver.findElement(By.xpath(".//*[@id='Fact-Communities-LIVE']"));
//List<WebElement> options = dropDown.findElements(By.xpath(".//*[@id='Fact-Communities-LIVE']/option[16]/text()"));
//driver.findElement(By.xpath(".//*[@id='Fact-Communities-LIVE']/option[16]")).click();

but seem to be something going wrong ..please any one guide me for these.

2
  • i used following xpath for the same <br>driver.findElement(By.xpath(".//*[@id='Fact-Communities-LIVE']/option[16]/text()='SHELL SUPPLIER QUALIFICATION SYSTEM'")).click(); Commented Sep 15, 2014 at 14:53
  • Your HTML is not properly formatted, which will cause problems for XPath. Your tooltip-title attribute (which I have never heard of) is not properly formatted as the right hand side of the equals is not followed by a double quote ("). Further, including HTML in a title attribute is a bit strange. You have additional embedded HTML in your select element that should not be there at all. <br /> tags do not need to follow <option> elements (and are in fact invalid) within a <select>. Try fixing these things first. validator.w3.org/#validate_by_input Commented Sep 15, 2014 at 14:57

2 Answers 2

1

Try below code

WebElelment dropDown = driver.findElement(By.id("Fact-Communities-LIVE"));
new Select(dropDown).selectByVisibleText("SHELL SUPPLIER QUALIFICATION SYSTEM");
or 
new Select(dropDown).selectByValue()("TxnyD.Communities.15.1");
Sign up to request clarification or add additional context in comments.

1 Comment

hi following error observed :at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299)at TestClass1.main(TestClass1.java:26) Caused by: rg.openqa.selenium.remote.ErrorHandler$UnknownServerException: Unable to locate element: {"method":"name","selector":"UploadNew"} Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'System info: host: 'ABGPC0066', ip: '10.187.3.191', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_20'Driver info: driver.version: unknown
0

Use the Select class:

Select select = new Select(driver.findElement(By.Id("Fact-Communities-LIVE");

and then use the option you want to select the options, by value, by text, by index etc. Also check all the tags on the html if all of them are properly open and closed

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.