V4.4 Selenium fix
This commit is contained in:
@@ -39,6 +39,47 @@ namespace AiQ_GUI
|
||||
return elementID;
|
||||
}
|
||||
|
||||
public static void SwitchUser(ChromeDriver driver)
|
||||
{
|
||||
try
|
||||
{
|
||||
WebDriverWait wait = new(driver, TimeSpan.FromSeconds(10));
|
||||
|
||||
// Click "Switch User"
|
||||
IWebElement switchBtn = wait.Until(d =>
|
||||
d.FindElement(By.XPath("//*[contains(text(),'Switch User')]"))
|
||||
);
|
||||
switchBtn.Click();
|
||||
|
||||
// Username
|
||||
IWebElement userBox = wait.Until(d => d.FindElement(By.Id("username")));
|
||||
userBox.Clear();
|
||||
userBox.SendKeys("admin");
|
||||
|
||||
// Password
|
||||
IWebElement passBox = wait.Until(d => d.FindElement(By.Id("password")));
|
||||
passBox.Clear();
|
||||
passBox.SendKeys("admin");
|
||||
|
||||
// Login button
|
||||
IWebElement loginBtn = wait.Until(d =>
|
||||
d.FindElement(By.XPath("//button[contains(normalize-space(text()), 'Login')]"))
|
||||
);
|
||||
|
||||
// Wait until it's clickable manually (no SeleniumExtras)
|
||||
wait.Until(d => loginBtn.Displayed && loginBtn.Enabled);
|
||||
|
||||
loginBtn.Click();
|
||||
|
||||
MainForm.Instance.AddToActionsList("Switched user and logged in.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("SwitchUser failed: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Attempts to click the web element with the specified ID; refreshes the page and retries once if the initial attempt fails
|
||||
public static void ClickElementByID(string elementID, ChromeDriver driver, bool tryagain = true)
|
||||
{
|
||||
@@ -65,16 +106,39 @@ namespace AiQ_GUI
|
||||
// Initialises and opens a ChromeDriver with specific options
|
||||
public static ChromeDriver OpenDriver()
|
||||
{
|
||||
ChromeDriverService chromeDriverService = ChromeDriverService.CreateDefaultService();
|
||||
chromeDriverService.HideCommandPromptWindow = true;
|
||||
ChromeOptions options = new();
|
||||
options.AddArguments("--app=data:,", "--window-size=960,1040", "--window-position=0,0");
|
||||
options.AddExcludedArgument("enable-automation");
|
||||
options.AddAdditionalChromeOption("useAutomationExtension", false);
|
||||
string tempProfile = null;
|
||||
|
||||
ChromeDriver driver = new(chromeDriverService, options);
|
||||
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(5);
|
||||
return driver;
|
||||
try
|
||||
{
|
||||
ChromeOptions options = new();
|
||||
options.AddArguments("--app=data:,",
|
||||
"--window-size=960,1040",
|
||||
"--window-position=0,0",
|
||||
"--no-sandbox",
|
||||
"--incognito",
|
||||
"--no-first-run",
|
||||
"--no-default-browser-check",
|
||||
"--disable-features=BrowserAddPersonFeature,InterestFeedContentSuggestions");
|
||||
|
||||
// Use a unique temporary profile to avoid conflicts
|
||||
tempProfile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
|
||||
options.AddArguments($"--user-data-dir={tempProfile}");
|
||||
|
||||
// manual driver path
|
||||
string driverPath = @"C:\ProgramData\MAV\AiQ_GUI";
|
||||
ChromeDriverService service = ChromeDriverService.CreateDefaultService(driverPath);
|
||||
service.HideCommandPromptWindow = true;
|
||||
|
||||
ChromeDriver driver = new(service, options);
|
||||
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(5);
|
||||
|
||||
return driver;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Failed to create ChromeDriver: " + ex.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
// Changes the value of a dropdown element by ID, logs the action, and verifies the result using flashline feedback
|
||||
|
||||
Reference in New Issue
Block a user