© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•11mo ago•
1 reply
Scrub

Selenium-unable to find element

Trying to run TestLogin(1st test) inside TestAddToCart(2nd test) then find an element afterwards, but unable to. I was able to find the element in the first test, but it doesn't seem to work in 2nd test. Not sure if it is allowed or there needs to be some kind of wait time.

[Test]
public void TestLogin()
{
//Test login automation
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://www.saucedemo.com/inventory.html");

Methods.EnterText(driver, By.Id("user-name"), "standard_user");
Methods.EnterText(driver, By.Id("password"), "secret_sauce");

driver.FindElement(By.Id("login-button")).Click();

//driver.FindElement(By.Name("add-to-cart-sauce-labs-backpack")).Click();
}

[Test]
public void TestAddToCart()
{
IWebDriver driver = new ChromeDriver();

TestLogin();

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement addToCartButton = wait.Until(ExpectedConditions.ElementToBeClickable(By.Name("add-to-cart-sauce-labs-backpack")));
addToCartButton.Click();
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Unable to find error.
C#CC# / help
4mo ago
Unable to find symbol file
C#CC# / help
14mo ago