Reputation: 11
I wrote a test script, using the chrome browser to simulate the phone mode. Text input is no problem, but the click event does not respond. An error message appears:
Click timed out after 60 seconds.
I used the following NuGet packages:
Selenium.Support 3.8.0
Selenium.WebDriver 3.8.0
Selenium.WebDriver.ChromeDriver 2.34.0
Below is my code:
ChromeOptions cos = new ChromeOptions();
string userAgent ="Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1";
//string userAgent = "Linux; Android 4.1.1; GT-N7100 Build/JRO03C) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/35.0.1916.138 Mobile Safari/537.36 T7/6.3";
cos.EnableMobileEmulation(new ChromeMobileEmulationDeviceSettings() { Width = 375, Height = 667, UserAgent = userAgent , EnableTouchEvents=true, PixelRatio=3.0 });
//cos.EnableMobileEmulation(new ChromeMobileEmulationDeviceSettings() { Width = 320, Height = 540, UserAgent = userAgent, EnableTouchEvents = true, PixelRatio = 3.0 });
IWebDriver driver = new ChromeDriver(cos);
driver.Manage().Window.Size = new System.Drawing.Size(395, 810);//
driver.Navigate().GoToUrl("https://m.baidu.com/");
Console.WriteLine("Page Loaded");
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
try
{
wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("index-kw")));
var item = driver.FindElement(By.Id("index-kw"));
item.SendKeys("selenium c#");
}
catch (Exception err)
{
Console.WriteLine(err.Message);
}
Console.WriteLine("text enter");
try
{
wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("index-bn")));
var item = driver.FindElement(By.Id("index-bn"));
item.Click();
}
catch (Exception err)
{
Console.WriteLine(err.Message);
}
Console.WriteLine("finished");
Console.ReadLine();
Upvotes: 0
Views: 617
Reputation: 139
I've had issues before with Click() that I assumed were due to whatever javascript executes on the button click conflicting with whatever Click() tries to do.
I've resolved them using item.SendKeys(Keys.Enter) instead. Might be worth a shot.
Upvotes: 1