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 in Selenium by Athira
• 130 points
127 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

0 votes
1 answer
+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
16,797 views
0 votes
1 answer
0 votes
1 answer

How to automate radio button and checkbox on a webpage in Selenium Webdriver?

Hey Yashmita, following code snippet automates the ...READ MORE

answered Jul 22, 2019 in Selenium by Anvi
• 14,090 points
807 views
0 votes
1 answer

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,510 points
3,078 views
0 votes
1 answer
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
2,342 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,890 points
2,487 views