0
votes

I am trying to go to a website, click 'Contact Us' and then search a term in the 'Ask shoppers!' search box. I tried to recreate the test in Selenium IDE but it wasn't capturing the search when I was recording. I am also unsure how to access the error logs to diagnose what is going wrong. So far I have:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;

namespace TestApplications
{
    class Program
    {
        static void Main(string[] args)
        {
            IWebDriver driver = new ChromeDriver(@"C:\Library");
            driver.Url = "http://www1.test.ca/en/Home";

            var findContact = driver.FindElement(By.CssSelector("#Header > section.hdr-bar > div > div > menu > ul > li:nth-child(2) > a"));
            findContact.Click();

            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));

            var findAsk = driver.FindElement(By.CssSelector("#response"));
            findAsk.SendKeys("text");
        } 
    }
}
1

1 Answers

1
votes

Because in that page there is an iframe with same ID response, while your target element is inside this frame with same ID.

<iframe id="response" height="70" marginheight="5" src="http://shoppers.mangomoon.ca/interact/customer_interface/question_form_sdm.jsp" frameborder="0" width="470" name="response" marginwidth="5"></iframe>

Therefore you need switch into the frame first.

IWebDriver driver = new ChromeDriver(@"C:\Library");
driver.Url = "http://www1.shoppersdrugmart.ca/en/Home";

var findContact = driver.FindElement(By.CssSelector("#Header > section.hdr-bar > div > div > menu > ul > li:nth-child(2) > a"));
findContact.Click();

driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));

driver.SwitchTo().Frame("response"); // add this for frame switching

var findAsk = driver.FindElement(By.CssSelector("#response"));
findAsk.SendKeys("text");