Python için Selenium'u kurmak için pip kullanın:
pip install selenium
Java için, pom.xml dosyanıza şunu ekleyin (Maven):
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.10.0</version>
</dependency>
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.get("https://www.example.com")
driver.get("https://www.example.com");
current_url = driver.current_url
String currentUrl = driver.getCurrentUrl();
title = driver.title
String title = driver.getTitle();
driver.quit()
driver.quit();
element = driver.find_element(By.ID, "elementId")
WebElement element = driver.findElement(By.id("elementId"));
element = driver.find_element(By.NAME, "elementName")
WebElement element = driver.findElement(By.name("elementName"));
element = driver.find_element(By.CLASS_NAME, "className")
WebElement element = driver.findElement(By.className("className"));
element = driver.find_element(By.CSS_SELECTOR, "#myId > div.class")
WebElement element = driver.findElement(By.cssSelector("#myId > div.class"));
element = driver.find_element(By.XPATH, "//input[@name='username']")
WebElement element = driver.findElement(By.xpath("//input[@name='username']"));
driver.implicitly_wait(10) # saniye
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "elementId"))
)
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;
WebElement element = new WebDriverWait(driver, Duration.ofSeconds(10))
.until(ExpectedConditions.presenceOfElementLocated(By.id("elementId")));
element.click()
element.click();
element.send_keys("Merhaba, Dünya!")
element.sendKeys("Merhaba, Dünya!");
element.clear()
element.clear();
element.submit()
element.submit();
import unittest
class TestimSinifi(unittest.TestCase):
def test_baslik(self):
self.assertEqual(driver.title, "Beklenen Başlık")
def test_element_metni(self):
element = driver.find_element(By.ID, "elementId")
self.assertEqual(element.text, "Beklenen Metin")
def test_element_ozellik(self):
element = driver.find_element(By.ID, "elementId")
self.assertEqual(element.get_attribute("class"), "beklenen-sinif")
import org.junit.Assert;
public class TestimSinifi {
@Test
public void testBaslik() {
Assert.assertEquals("Beklenen Başlık", driver.getTitle());
}
@Test
public void testElementMetni() {
WebElement element = driver.findElement(By.id("elementId"));
Assert.assertEquals("Beklenen Metin", element.getText());
}
@Test
public void testElementOzellik() {
WebElement element = driver.findElement(By.id("elementId"));
Assert.assertEquals("beklenen-sinif", element.getAttribute("class"));
}
}
alert = driver.switch_to.alert
alert.accept()
Alert alert = driver.switchTo().alert();
alert.accept();
alert = driver.switch_to.alert
alert.dismiss()
Alert alert = driver.switchTo().alert();
alert.dismiss();
alert = driver.switch_to.alert
alert_text = alert.text
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
# İndeks ile
driver.switch_to.frame(0)
# İsim veya ID ile
driver.switch_to.frame("cerceve_ismi")
# WebElement ile
cerceve_elementi = driver.find_element(By.TAG_NAME, "iframe")
driver.switch_to.frame(cerceve_elementi)
// İndeks ile
driver.switchTo().frame(0);
// İsim veya ID ile
driver.switchTo().frame("cerceve_ismi");
// WebElement ile
WebElement cerceve_elementi = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(cerceve_elementi);
# Yeni pencereye geçiş
orijinal_pencere = driver.current_window_handle
for pencere_tanimlayicisi in driver.window_handles:
if pencere_tanimlayicisi != orijinal_pencere:
driver.switch_to.window(pencere_tanimlayicisi)
break
// Yeni pencereye geçiş
String orijinalPencere = driver.getWindowHandle();
for (String pencereTanimlayicisi : driver.getWindowHandles()) {
if(!orijinalPencere.contentEquals(pencereTanimlayicisi)) {
driver.switchTo().window(pencereTanimlayicisi);
break;
}
}
js_kodu = "return document.title;"
baslik = driver.execute_script(js_kodu)
String jsKodu = "return document.title;";
String baslik = (String) ((JavascriptExecutor) driver).executeScript(jsKodu);
driver.save_screenshot("ekran_goruntusu.png")
File ekranGoruntusu = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
Files.copy(ekranGoruntusu.toPath(), Paths.get("ekran_goruntusu.png"));
dosya_girisi = driver.find_element(By.ID, "dosyaGirisi")
dosya_girisi.send_keys("/yol/dosya.txt")
WebElement dosyaGirisi = driver.findElement(By.id("dosyaGirisi"));
dosyaGirisi.sendKeys("/yol/dosya.txt");
2024 © Tüm hakları saklıdır - buraxta.com