After selecting a product and opening it in another page Im not able to click on add to cart button in amazon using selenium webdriver with c sharp visual studio

+1 vote
Jul 8, 2020 in Selenium by Athira
• 130 points
Hey @Athira, could you please post the error as well as the code snippet that you are using?
public void Email()
            Excel.Application MyApp = null;
            Excel.Workbook MyBook = null;
            Excel.Worksheet MySheet = null;

            MyApp = new Excel.Application();
            MyApp.Visible = true;

            MyBook = MyApp.Workbooks.Open(@"C:\Users\anoop\Desktop\AmazonExcel.xlsx");
            MySheet = MyBook.Sheets["Cart"];

            int row_count = MySheet.UsedRange.Rows.Count;

            int col_count = MySheet.UsedRange.Columns.Count;

            for (int i = 2; i <= row_count; i++)
                String pname = MySheet.Cells[i, 1].Text;

                driver.FindElement(By.Id("twotabsearchtextbox")).SendKeys(pname +Keys.Enter);
                driver.FindElement(By.XPath("//span[@class='a-size-medium a-color-base a-text-normal']")).Click();
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(50);


This is the code snippet that im using, there aren't any error messages just that the test is failing and the add to cart button is not being clicked.

Try adding a wait time for the button to be clickable like in 

WebDriverWait(driver, 10).until(EC.element_to_be_clickable(By.CSS_SELECTOR, elem), or visible/presence located through WebDriverWait. 

You can maybe use actions like

actions = Actionchains(driver) 

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Selenium

+1 vote
2 answers
+1 vote
2 answers
+1 vote
2 answers

Is it possible to scroll down in a webpage using selenium webdriver programmed on python?

I using next code for facebook for ...READ MORE

answered May 16, 2019 in Selenium by
0 votes
1 answer
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2, 2020 in Selenium by Sri
• 3,190 points