728x90
JQuery 추가하기
var script = document.createElement("script");
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js";
document.getElementsByTagName("head")[0].appendChild(script);
JQuery 실행
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://www.example.com");
IWebElement element = (IWebElement) driver.ExecuteScript("return $('#element-id').val();");
string value = element.GetAttribute("value");
Console.WriteLine(value);
윈도우 핸들 탭변경
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
IWebDriver driver = new ChromeDriver();
// Get the current window handle
string originalWindowHandle = driver.CurrentWindowHandle;
// Click a link that opens a new tab
IWebElement link = driver.FindElement(By.LinkText("Open in new tab"));
link.Click();
// Wait for the new tab to be created
int waitCount = 0;
while (driver.WindowHandles.Count == 1 && waitCount < 10)
{
System.Threading.Thread.Sleep(1000);
waitCount++;
}
// Get the new window handle
string newWindowHandle = driver.WindowHandles[1];
// Switch to the new tab
driver.SwitchTo().Window(newWindowHandle);
// Do your work on the new tab
// Close the new tab and switch back to the original tab
driver.Close();
driver.SwitchTo().Window(originalWindowHandle);
728x90
728x90