2016-07-24 26 views
1

我正在嘗試使用salesforce和selenium創建一個自動化腳本來記錄呼叫。我已經能夠讓我的腳本加載網站,登錄並導航到「我的帳戶」頁面。在該頁面上有一張所有帳戶的表格。我試圖點擊一個特定的帳戶,但我無法讓Selenium找到該元素。以下是表中的每個元素看起來像:Selenium和Salesforce Automation從我的賬戶頁面中點擊一個特定的賬戶

<tr class="dataRow even" onmouseover="if (typeof(hiOn) != 'undefined') {hiOn(this);}" onblur="if (typeof(hiOff) != 'undefined'){hiOff(this);}" onfocus="if (typeof(hiOn) != 'undefined'){hiOn(this);}" onmouseout="if (typeof(hiOff) != 'undefined'){hiOff(this);}"> 
<td> 
<input id="001U000000nyG6oIAE" type="checkbox" onchange="com.vod309.myaccounts.addOrRemoveAcct(this)"> 
<input id="isPerson" type="hidden" value="false"> 
</td> 
<td class="dataCell"> 
<a target="_top" href="https://na12.salesforce.com/001U000000nyG6oIAE">CAP AREA SPCH CENTER</a> 
</td> 
</tr> 

誰能幫我把我的腳本來正確地點擊鏈接進入「CAP AREA SPCH中心」?

我已經嘗試:

driver.findElement(By.linkText("CAP AREA SPCH CENTER")).click(); 
driver.findElement(By.xpath("//table/tbody/tr[55]/td[2]/a").click(); 

和很多人一樣,但由於某些原因,它不能正確找到鏈接。我想這可能是因爲鏈接在表格中?任何幫助將不勝感激,謝謝。

+0

你是什麼意思'它不正確地找到鏈接???是否有任何異常? –

+0

它給了我例外,「沒有這樣的元素」。即使正如您在上面張貼的部分中看到的那樣,其中包含「CAP AREA SPCH CENTER」的元素 –

+0

請檢查您的元素是否位於任何幀或Iframe內......如果需要先切換該幀作爲: - 'driver.switchTo()。frame(「frame name or id」);'.. –

回答

0

你應該實現WebDriverWait等到元素可見,使以如下點擊: -

WebDriverWait wait = new WebDriverWait(driver, 10); 
wait.until(ExpectedConditions.elementToBeClickable(By.linkText("CAP AREA SPCH CENTER"))).click(); 

或者

wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(.,'CAP AREA SPCH CENTER')]"))).click(); 

編輯: - 你需要先切換的iFrame然後去查找元素如下: -

driver.switchTo().frame("itarget"); 

WebDriverWait wait = new WebDriverWait(driver, 10); 
    wait.until(ExpectedConditions.elementToBeClickable(By.linkText("CAP AREA SPCH CENTER"))).click(); 

希望它有幫助.. :)

+0

感謝您的幫助,但不幸的是這些工作都沒有,我認爲這個問題是與Salesforce網站 –

+0

@PhillipPowell你是什麼意思,這些都不是工作..有什麼異常?並確保此元素不在任何框架或iframe中? –

+0

請檢查可能是存在任何幀... –

0

你試過find_element_by_link_text

elem = driver.find_element_by_link_text("CAP AREA SPCH CENTER") 
elem.click() 
+0

是不是像driver.findElement相同(By.linkText(「CAP AREA SPCH CENTER」))。click();?我是新來的硒,所以我不知道 –