2016-12-28 13 views
0

をキャプチャ:セレンやFirefoxを使用して、私は他のものの間で取得する私のWebアプリ、私はオブジェクトをcaprtureするために使用することができると思うこのコードでリンクをマーキング対象物

cb_or_somename_someothername cb_area_0219 

この文字列は、「クラス名」ですFirebugで

WebElement rolle = driver.findElement(By.className("cb_or_somename_someothername cb_area_0219")); 

しかし、実行時にスクリプトが要素を見つけることができません: は私が入力したスクリプトに行きます。 Firebugのパネルでonfoその他

は次のとおりです。

class="cb_or_somename_someothername cb_area_0219" 


onclick="jsf.util.chain(this,event,'$(this).attr(\'disabled\', \'disabled\');return true;','mojarra.jsfcljs(document.getElementById(\'fwMainContentForm\'),{\'fwMainContentForm:j_idt156:2:selectRole \':\'fwMainContentForm:j_idt156:2:selectRole\'},\'\')');return false" 


href="#" 


id="fwMainContentForm:j_idt156:2:selectRole" 

は間違った方法で要素を参照する私のスクリプトですか?

+0

複合クラス名については、「ElementNotFoundException」または例外がありますか? – Andersson

+0

原因:org.openqa.selenium.InvalidSelectorException:指定されたセレクタcb_or_somename_someothername cb_area_0219が無効か、WebElementになりません。次のエラーが発生しました: InvalidSelectorError:複合クラス名は許可されていません このエラーに関する説明は、http://seleniumhq.org/exceptions/invalid_selector_exception.htmlを参照してください。 ビルドインフォメーション:バージョン: '2.53.1'、改訂: 'a36b8b1cd5757287168e54b817830adce9b0158d'、時刻: '2016-06-30 19:26:09' –

答えて

0

化合物クラス名(名前はスペースで区切って)で検索することはできません。代わりにCSSセレクタで検索を使用するようにしてください:

WebElement rolle = driver.findElement(By.cssSelector(".cb_or_somename_someothername.cb_area_0219")); 

またはXPathによって:

WebElement rolle = driver.findElement(By.xpath("//*[@class='cb_or_somename_someothername cb_area_0219']")); 

また、あなたはまだ2つのクラス名のいずれかで検索を使用することができます。

WebElement rolle = driver.findElement(By.className("cb_or_somename_someothername")); 

または

WebElement rolle = driver.findElement(By.className("cb_area_0219")); // Note that this class name could be generated dynamically, so each time it could has different decimal part 

更新

Element is not clickable...例外が発生した場合、その要素をクリックしようとすると別の要素で覆われているように見えます。したがって、この「カバー」が見えなくなるまで待つようにしてください:

new WebDriverWait(driver, 10).until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//p[@class='environtment-banner']")); 
WebElement rolle = driver.findElement(By.className("cb_area_0219")); 
rolle.click(); 
+0

コメントは議論の対象外です。この会話は[チャットに移動]されています(http://chat.stackoverflow.com/rooms/131898/discussion-on-answer-by-andersson-selenium-and-capture-object)。 –

関連する問題