2017-03-27 1 views
0

J'ai essayé de cliquer sur le bouton 'Connexion'. mais il ne clique pas du tout. mon code est ci-dessous. Quelqu'un peut-il m'aider?C# Comment cliquer sur le bouton à l'aide du pilote Web Sélénium?

[FindsBy(How = How.XPath, Using = "//input[@name='ctl00$MainContent$LoginForm$LoginButton' and @value='sign in']")] 
    [CacheLookup] 
    private IWebElement Submit { get; set; } 

    public LoginPage(IWebDriver driver) 
    { 
     this.driver = driver; 
     PageFactory.InitElements(driver, this); 
    } 

    public void LoginToApplication() 
    { 
     System.Threading.Thread.Sleep(5000); 
     Submit.Click(); 
    } 

enter image description here

+0

Veuillez poster le code HTML au lieu d'une image. – JeffC

Répondre

2

Essayez l'une de ces Mentionnés ci-dessous xpath.

//button[text()='sign in'] 

Explication: - Utilisez la méthode text avec tag <button>.

OU

//button[@class='color'][text()='sign in'] 

Explication: - Utilisez class attribut et méthode text avec tag <button>.

OU

//button[@type='button'][text()='sign in'] 

Explication: - Utilisez type attribut et méthode text avec tag <button>.

Suggestion: - Au lieu d'utiliser absolute xpath, utilisez relative xpath.

+0

Oui Ça marche! Vous êtes le meilleur merci – everline