質問

I'm trying to use java and selenium to select an option from the dropdown menu from a site. I'm able to click size 7 because of the unique class name. However I'm unable to click size 9 or 10.5 like I would like to. So i would like to know if I would be able to click based on the rel attribute?

<li class="nsg-form--drop-down--option  first-in-row upper-left" rel="3161894:7"> 7 </li>
<li class="nsg-form--drop-down--option" rel="3161895:7.5"> 7.5 </li>
<li class="nsg-form--drop-down--option last-in-row upper-right" rel="3161896:8"> 8 </li>
<li class="nsg-form--drop-down--option first-in-row" rel="3161897:8.5"> 8.5 </li>
<li class="nsg-form--drop-down--option" rel="3161898:9"> 9 </li>
<li class="nsg-form--drop-down--option last-in-row" rel="3161899:9.5"> 9.5 </li>
<li class="nsg-form--drop-down--option first-in-row" rel="3161900:10"> 10 </li>
<li class="nsg-form--drop-down--option" rel="3161901:10.5"> 10.5 </li>
<li class="nsg-form--drop-down--option last-in-row" rel="3161902:11"> 11 </li>
<li class="nsg-form--drop-down--option first-in-row" rel="3161903:11.5"> 11.5 </li>

I've tried:

selenium.click("rel=3161898");
selenium.mouseDown("rel=3161898);
selenium.mouseUp("rel=3161898);
役に立ちましたか?

解決

I'm not too familiar with Selenium-RC, but you should try CSS Selector or XPath here.

// CSS Selector
selenium.click("css=li.nsg-form--drop-down--option[rel$=':9']"); // rel ends with :9
selenium.click("css=li.nsg-form--drop-down--option[rel^='3161898']"); // rel starts with 3161898

// XPath
selenium.click("xpath=//li[contains(@class, 'nsg-form--drop-down--option') and contains(@rel, ':9')]");
selenium.click("xpath=//li[contains(@class, 'nsg-form--drop-down--option') and starts-with(@rel, '3161898')]");

他のヒント

I feel if it is a element in the dropdown menu, then use the following syntax to select that element:

selenium.select("locator of the dropdown","Index= indexno.");

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top