30 Mayıs 2019 Perşembe

Selenium By Sınıfı

Giriş
Selenium ile locator olarak şu yöntemler kullanılabilir.
Id Locator
Name Locator
Class Locator
Tag Name Locator
Link Text
Partial Link Text Locator
XPath Locator
CSS Selector
id metodu
Şöyle yaparız.
driver.findElement(By.id("ap_email")).click();
linkText metodu
Şöyle yaparız
WebElement functionAnchor = driver.findElement(By.linkText(functionName));
name metodu
Açıklaması şöyle. Aynı isme sahip bir çok nesne olabilir. Bu durumda findElement() ilk bulduğunu döner.
The name locator in Selenium is used to identify the elements of a webpage. This attribute can be mentioned as part of multiple tags like < input >, < button >, < select >. Unlike ID, this may or may not be unique to a page. A webpage may contain multiple tags with the same name attribute value. In such a case, if your intent is to select your desired element, the name locator in Selenium may not be the correct choice.

A key point to note is when you select an element with a desired name attribute value, it will select the first element it encounters. You may come across another scenario, where you wish to select elements with the same name attribute value, in this case, the Name locator in Selenium may work using the findElements syntax.
Örnek
Şöyle yaparız.
driver.findElement(By.name("username")).sendKeys("name.surname");
driver.findElement(By.name("password")).sendKeys("Huhuhu");
tagName metodu
Şöyle yaparız.
driver.findElement(By.tagName("body")).sendKeys(Keys.CONTROL + "t");
xpath metodu
Örnek
Şöyle yaparız.
driver.findElement(By.xpath("//a [@href='https://www.snapdeal.com/login']"))
  .click();
Örnek
Elimizde şöyle bir kod olsun.
<button type="button" id="ext-gen72" class=" x-btn-text tdgi_icon_key">LogIn</button>
Şöyle yaparız.
By.xpath("//button[contains(., 'LogIn']")

Hiç yorum yok:

Yorum Gönder