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 9, 2020 in Selenium by Athira
• 130 points
3,234 views
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;
            Console.WriteLine(row_count);

            int col_count = MySheet.UsedRange.Columns.Count;
            Console.WriteLine(col_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);
                Thread.Sleep(1000);
                driver.FindElement(By.XPath("//span[@class='a-size-medium a-color-base a-text-normal']")).Click();
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(50);
                driver.FindElement(By.Id("add-to-cart-button")).Click();

            }
            MyBook.Close();
            MyApp.Quit();

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) 
actions.move_to_element(elem).perform().click()

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 mslavikas@gmail.com
26,107 views
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
13,776 views
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
9,191 views
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,910 points
7,267 views
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 3, 2020 in Selenium by Sri
• 3,190 points
7,904 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP