2017-01-08 4 views
0

Ich hatte eine HTML-Schaltfläche mit id = submit, also Selenium IDE verwenden Ich wählte den Befehl "Click" mit Ziel als ID = Submit aber Selen IDE diese Zeile übergeben, als ob es ausgeführt wird, aber ohne die Schaltfläche wirklich geklickt, damit das Formular nicht gesendet wird !! Was ist falsch ?Selenium führt keinen Klickbefehl aus

Hier ist der C# -Code, den ich exportiert habe. Das Problem ist in driver.FindElement(By.Name("submit")).Click();

using System; 
using System.Text; 
using System.Text.RegularExpressions; 
using System.Threading; 
using NUnit.Framework; 
using OpenQA.Selenium; 
using OpenQA.Selenium.Firefox; 
using OpenQA.Selenium.Support.UI; 

namespace SeleniumTests 
{ 
    [TestFixture] 
    public class Web 
    { 
     private IWebDriver driver; 
     private StringBuilder verificationErrors; 
     private string baseURL; 
     private bool acceptNextAlert = true; 

     [SetUp] 
     public void SetupTest() 
     { 
      driver = new FirefoxDriver(); 
      baseURL = "I cannot share url"; 
      verificationErrors = new StringBuilder(); 
     } 

     [TearDown] 
     public void TeardownTest() 
     { 
      try 
      { 
       driver.Quit(); 
      } 
      catch (Exception) 
      { 
       // Ignore errors if unable to close the browser 
      } 
      Assert.AreEqual("", verificationErrors.ToString()); 
     } 

     [Test] 
     public void TheWebTest() 
     { 
      driver.Navigate().GoToUrl("I cannot share url"); 
      driver.FindElement(By.Id("submit")).Click(); 
      for (int second = 0;; second++) { 
       if (second >= 60) Assert.Fail("timeout"); 
       try 
       { 
        if ("All Campaigns" == driver.FindElement(By.CssSelector("#CampaignsTable > div.box > div.title")).Text) break; 
       } 
       catch (Exception) 
       {} 
       Thread.Sleep(1000); 
      } 
      for (int second = 0;; second++) { 
       if (second >= 60) Assert.Fail("timeout"); 
       try 
       { 
        if ("Last" == driver.FindElement(By.Id("cloaker_last")).Text) break; 
       } 
       catch (Exception) 
       {} 
       Thread.Sleep(1000); 
      } 
      driver.FindElement(By.XPath("(//img[@alt='Click to edit the rotator settings'])[1]")).Click(); 
      driver.FindElement(By.Id("addNewUrl_0_geo_0_url_to_cloak")).Clear(); 
      driver.FindElement(By.Id("addNewUrl_0_geo_0_url_to_cloak")).SendKeys("dghfghf"); 
      driver.FindElement(By.Id("addNewUrl_0_geo_0_mobile_url")).Click(); 
      driver.FindElement(By.Id("submit")).Click(); 
      driver.FindElement(By.Id("submit")).Click(); 
      for (int second = 0;; second++) { 
       if (second >= 60) Assert.Fail("timeout"); 
       try 
       { 
        if ("Success" == driver.FindElement(By.CssSelector("div.message.green > span > b")).Text) break; 
       } 
       catch (Exception) 
       {} 
       Thread.Sleep(1000); 
      } 
      driver.FindElement(By.XPath("(//img[@alt='Click to edit the rotator settings'])[2]")).Click(); 
      driver.FindElement(By.Id("addNewUrl_0_geo_0_url_to_cloak")).Clear(); 
      driver.FindElement(By.Id("addNewUrl_0_geo_0_url_to_cloak")).SendKeys("tyujghghj"); 
      driver.FindElement(By.Name("submit")).Click(); 
      driver.FindElement(By.XPath("(//img[@alt='Click to edit the rotator settings'])[3]")).Click(); 
      driver.FindElement(By.Id("addNewUrl_0_geo_0_url_to_cloak")).Clear(); 
      driver.FindElement(By.Id("addNewUrl_0_geo_0_url_to_cloak")).SendKeys("gfhjghjgh"); 
      driver.FindElement(By.Name("submit")).Click(); 
      driver.FindElement(By.XPath("(//img[@alt='Click to edit the rotator settings'])[4]")).Click(); 
      driver.FindElement(By.Id("addNewUrl_0_geo_0_url_to_cloak")).Clear(); 
      driver.FindElement(By.Id("addNewUrl_0_geo_0_url_to_cloak")).SendKeys("ghghkghk"); 
      driver.FindElement(By.Id("addNewUrl_0_geo_0_mobile_url")).Click(); 
      driver.FindElement(By.Name("submit")).Click(); 
     } 
     private bool IsElementPresent(By by) 
     { 
      try 
      { 
       driver.FindElement(by); 
       return true; 
      } 
      catch (NoSuchElementException) 
      { 
       return false; 
      } 
     } 

     private bool IsAlertPresent() 
     { 
      try 
      { 
       driver.SwitchTo().Alert(); 
       return true; 
      } 
      catch (NoAlertPresentException) 
      { 
       return false; 
      } 
     } 

     private string CloseAlertAndGetItsText() { 
      try { 
       IAlert alert = driver.SwitchTo().Alert(); 
       string alertText = alert.Text; 
       if (acceptNextAlert) { 
        alert.Accept(); 
       } else { 
        alert.Dismiss(); 
       } 
       return alertText; 
      } finally { 
       acceptNextAlert = true; 
      } 
     } 
    } 
} 

Antwort

0

Vielleicht, wenn Sie vorhandenen Code gemeinsam, die URL Sie zu verweisen versuchen, etc. wir mehr hilfreich sein könnten.

Es ist sehr schwierig, eine Frage ohne ausreichende Informationen zu beantworten.

0

Sie haben den Code nicht geteilt, daher ist es schwierig, Ihr Problem zu analysieren. Dies könnte Ihnen helfen -

ändern Sie einfach Ihren Befehl click zu clickAt und dann versuchen.

+0

selben Problem, ich benutze die IDE – Wel

Verwandte Themen