Skip to content

Commit b21a4f5

Browse files
committed
Fixing issue #1479. The only reasonable thing we can do for select elements is to disable clickability checking, see https://gist.github.com/p0deje/c549e93fa19bf7aaee49
1 parent d57afc1 commit b21a4f5

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

common/src/web/selectPage.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,12 @@
4747
<option>five</option>
4848
<option>six</option>
4949
</select>
50+
51+
<select id="narrow" style="width: 50px;">
52+
<option value="evalon">LaClare Farms Evalon with Cummin</option>
53+
<option value="savourine">Yarra Valley Vintage Savourine</option>
54+
<option value="cheddar">Avonlea Clothbound Cheddar</option>
55+
</select>
56+
5057
</body>
5158
</html>

java/client/test/org/openqa/selenium/support/ui/SelectElementTest.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.junit.Before;
2727
import org.junit.Test;
2828
import org.openqa.selenium.By;
29+
import org.openqa.selenium.NoSuchElementException;
2930
import org.openqa.selenium.WebElement;
3031
import org.openqa.selenium.testing.Ignore;
3132
import org.openqa.selenium.testing.JUnit4TestBase;
@@ -39,7 +40,7 @@ public void runBeforeEveryTest() {
3940
driver.get(pages.formPage);
4041
}
4142

42-
@Test(expected = org.openqa.selenium.support.ui.UnexpectedTagNameException.class)
43+
@Test(expected = UnexpectedTagNameException.class)
4344
public void shouldThrowAnExceptionIfTheElementIsNotASelectElement() {
4445
WebElement selectElement = driver.findElement(By.name("checky"));
4546
Select select = new Select(selectElement);
@@ -141,7 +142,7 @@ public void shouldReturnFirstSelectedOption() {
141142
assertEquals("Eggs",firstSelected.getText());
142143
}
143144

144-
@Test(expected = org.openqa.selenium.NoSuchElementException.class)
145+
@Test(expected = NoSuchElementException.class)
145146
public void shouldThrowANoSuchElementExceptionIfNothingIsSelected() {
146147
WebElement selectElement = driver.findElement(By.name("select_empty_multiple"));
147148
Select select = new Select(selectElement);
@@ -158,14 +159,14 @@ public void shouldAllowOptionsToBeSelectedByVisibleText() {
158159
assertEquals("select_2",firstSelected.getText());
159160
}
160161

161-
@Test(expected = org.openqa.selenium.NoSuchElementException.class)
162+
@Test(expected = NoSuchElementException.class)
162163
public void shouldNotAllowInvisibleOptionsToBeSelectedByVisibleText() {
163164
WebElement selectElement = driver.findElement(By.name("invisi_select"));
164165
Select select = new Select(selectElement);
165166
select.selectByVisibleText("Apples");
166167
}
167168

168-
@Test(expected = org.openqa.selenium.NoSuchElementException.class)
169+
@Test(expected = NoSuchElementException.class)
169170
public void shouldThrowExceptionOnSelectByVisibleTextIfOptionDoesNotExist() {
170171
WebElement selectElement = driver.findElement(By.name("select_empty_multiple"));
171172
Select select = new Select(selectElement);
@@ -181,7 +182,7 @@ public void shouldAllowOptionsToBeSelectedByIndex() {
181182
assertEquals("select_2",firstSelected.getText());
182183
}
183184

184-
@Test(expected = org.openqa.selenium.NoSuchElementException.class)
185+
@Test(expected = NoSuchElementException.class)
185186
public void shouldThrowExceptionOnSelectByIndexIfOptionDoesNotExist() {
186187
WebElement selectElement = driver.findElement(By.name("select_empty_multiple"));
187188
Select select = new Select(selectElement);
@@ -197,7 +198,7 @@ public void shouldAllowOptionsToBeSelectedByReturnedValue() {
197198
assertEquals("select_2",firstSelected.getText());
198199
}
199200

200-
@Test(expected = org.openqa.selenium.NoSuchElementException.class)
201+
@Test(expected = NoSuchElementException.class)
201202
public void shouldThrowExceptionOnSelectByReturnedValueIfOptionDoesNotExist() {
202203
WebElement selectElement = driver.findElement(By.name("select_empty_multiple"));
203204
Select select = new Select(selectElement);
@@ -215,7 +216,7 @@ public void shouldAllowUserToDeselectAllWhenSelectSupportsMultipleSelections() {
215216
assertEquals(0,returnedOptions.size());
216217
}
217218

218-
@Test(expected = java.lang.UnsupportedOperationException.class)
219+
@Test(expected = UnsupportedOperationException.class)
219220
public void shouldNotAllowUserToDeselectAllWhenSelectDoesNotSupportMultipleSelections() {
220221
WebElement selectElement = driver.findElement(By.name("selectomatic"));
221222
Select select = new Select(selectElement);
@@ -232,7 +233,7 @@ public void shouldAllowUserToDeselectOptionsByVisibleText() {
232233
assertEquals(1,returnedOptions.size());
233234
}
234235

235-
@Test(expected = org.openqa.selenium.NoSuchElementException.class)
236+
@Test(expected = NoSuchElementException.class)
236237
public void shouldNotAllowUserToDeselectOptionsByInvisibleText() {
237238
WebElement selectElement = driver.findElement(By.name("invisi_select"));
238239
Select select = new Select(selectElement);
@@ -258,4 +259,15 @@ public void shouldAllowOptionsToBeDeselectedByReturnedValue() {
258259

259260
assertEquals(1,returnedOptions.size());
260261
}
262+
263+
@Test
264+
public void shouldAllowOptionsToBeSelectedFromTheSelectElementThatIsNarrowerThanOptions() {
265+
driver.get(pages.selectPage);
266+
WebElement selectElement = driver.findElement(By.id("narrow"));
267+
Select select = new Select(selectElement);
268+
select.selectByIndex(1);
269+
List<WebElement> returnedOptions = select.getAllSelectedOptions();
270+
271+
assertEquals(1,returnedOptions.size());
272+
}
261273
}

javascript/firefox-driver/js/syntheticMouse.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ SyntheticMouse.prototype.isElementClickable = function(element) {
108108

109109
var tagName = element.tagName.toLowerCase();
110110

111+
// TODO: https://gist.github.com/p0deje/c549e93fa19bf7aaee49
112+
if ('select' == tagName) {
113+
return;
114+
}
115+
111116
// Check to see if this is an option element. If it is, and the parent isn't a multiple
112117
// select, then check that select is clickable.
113118
if ('option' == tagName) {
@@ -283,11 +288,12 @@ SyntheticMouse.prototype.click = function(target) {
283288
}
284289

285290
if (parent && parent.tagName.toLowerCase() == 'select' && !parent.multiple) {
291+
goog.log.info(SyntheticMouse.LOG_, 'About to do a bot.action.click on ' + element);
286292
bot.action.click(parent, undefined /* coords */);
287293
}
288294

289295
goog.log.info(SyntheticMouse.LOG_, 'About to do a bot.action.click on ' + element);
290-
bot.action.click(element, this.lastMousePosition, new bot.Mouse(null, this.modifierKeys));
296+
bot.action.click(element, undefined, new bot.Mouse(null, this.modifierKeys));
291297

292298
} else {
293299
goog.log.info(SyntheticMouse.LOG_, 'About to do a bot.action.click on ' + element);

0 commit comments

Comments
 (0)