Tuesday, 15 April 2014

java - Selenium Webdriver cannot choose a value in a dropdown list -


I am trying to use selenium Webdriver to java I am Actually, I have a website with empty fields. After the user clicks on the field, a drop-down list with 5 options will appear and the user will have to choose an option.

Codes look like this

   

I tried to use this Java code to choose option 2

WebDriverWait wait = new WebDriverWait (driver, 100); Wait.until (ExpectedConditions.visibilityOfElementLocated (By.cssSelector ("form row.print- escape-page break & gt; label"))); // Start the ID to search the element dynamically loads the page every time the system loads, the last part is created dynamically except the TaskID, thus selecting the string TaskID selection dropdown = new (driver.findElement ( By.xpath (".//// [contains (@id 'TaskId')]"))); Dropdown.selectByValue ("OPT2");

selenium returns error

org.openqa.selenium.ElementNotVisibleException: element is not visible: element is not currently visible And possibly it can not be controlled

I feel that this & lt; Div class = "subhidden" & gt; , but I'm not even sure. Any suggestion is highly appreciated. Thank you.

The test code block below shows up and looks fine. Looking at html , this is a fair assumption that the selector does not return the specific element. I believe that you want to have id TaskId Select Tag. Just a tag-dependent search probably selects // [in it (id id, 'task id')] since has the same text with the same text TaskId and going forward I will give you the Xpath Before I check, I suggest asking for testing in the test at least to my experience.

  WebDriverWait wait = new WebDriverWait (driver, 100); SelectElementSelector = By.xpath ("// selection [in (ID id, 'TaskID']]"); Select Web Element Element = Wait. Ultimately (Expected Conditions. Index Submissions (Selection Elight Selection)); Select dropdown = choose new (select element); Dropdown.selectByValue ("OPT2");  

Edit

Another possible option is to find the element with options with a proper selector. Then, you have to test the selector to make sure it is unique and this is what you want.

  WebDriverWait wait = new WebDriverWait (driver, 100); String option tocect = "OPT1"; // Selector is the move here: selectElementSelector = By.cssSelector ("[id * = 'TaskId']> Select the option [value = '' + optionto + + '']"); Wait.until (ExpectedConditions Click on .presenceOfElementLocated (selectElementSelector));  

No comments:

Post a Comment