2017-08-14 95 views
1

我遇到這些最後一行工作的問題。最後的搜索按鈕部分是它的中斷點。它說「未知錯誤:無法聚焦元素」。最後一行僅僅是單擊搜索按鈕。硒Web驅動程序單擊

這裏是html代碼即時通訊從它。這是搜索按鈕代碼。

<img class="Banner-Search-Type-search-ImageStyle" 
src="images/BannerImages/go-img.png" id="btnsearch"> 

這是我的代碼。

var mfgPartNumber = "CRCW12061R00FKEA"; 
     IWebDriver driver=new ChromeDriver(@"C:\Users\josimpso\AppData\Roaming"); 
     driver.Navigate().GoToUrl("https://app.siliconexpert.com/CMOMFX/customerlogin.html"); 
     //Set Username 
     IWebElement setUserName = driver.FindElement(By.ClassName("logininput")); 
     setUserName.SendKeys("userName"); 
     //Set Password 
     IWebElement setPassword = driver.FindElement(By.Name("password")); 
     setPassword.SendKeys("Password"); 
     // Click login button 
     IWebElement loginButton = driver.FindElement(By.Id("loginsubmit")); 
     loginButton.SendKeys(OpenQA.Selenium.Keys.Enter); 

     // Now search based on mfgPartNumber 
     IWebElement searchBox = driver.FindElement(By.Id("txtsearch")); 
     searchBox.SendKeys(mfgPartNumber); 
     // Press enter on the search 
     IWebElement searchButton = driver.FindElement(By.Id("btnsearch")); 
     searchButton.SendKeys(OpenQA.Selenium.Keys.Enter); 
+0

此外,如何使發送鍵右鍵單擊該按鈕?不要點擊輸入。點擊輸入將不會搜索go按鈕。 – weknowgp

+0

爲什麼你不只是得到按鈕By.Id就像你用txtsearch文本框做的那樣? – Fran

+0

這也沒有工作。我剛試過這個。我將它切換到Id。 Id也不起作用。 – weknowgp

回答

1

不幸的是,我現在無法對其進行測試,但您的圖片應該位於<a>標記內。您在<a>標記中執行單擊,而不是在圖像中

0

可能是由於SendKeys,它未成功發送。

而不是SendKeys,嘗試使用ActionClass,這是另一種發送密鑰的方式。

對於e.g,

Actions new_action = new Actions(driver); 

new_action.sendKeys("VALUE");