Interview Questions

Can you list some of the webpage operations available in Selenium?

Me: Sure! Some of the main operations are:

♻️ Navigate to URLs:

driver.get("url") 🖥
driver.navigate().to("url") 🏎️

👀 Inspect the webpage:

driver.getTitle() 📃
driver.getPageSource() 👁
driver.getCurrentUrl() 🌐

✍️ Interact with elements:

driver.find_element_by_id().send_keys("text") 🔍
driver.find_elements_by_class_name().click() 🖱

📷 Take screenshots:

driver.get_screenshot_as_file("filename.png") 📸

⌨️ Send keyboard inputs:

Actions().send_keys().perform() 💻

🖱 Perform mouse actions:

Actions().move_to_element().click().perform() 🖱

What WebEdit operations are available in Selenium?

Me: WebEdit refers to text fields, input boxes, and text areas on a webpage. Selenium provides these useful APIs to interact with WebEdits:

To enter text in a text field:

sendKeys()

Syntax:

driver.findElement([By.id](<http://by.id/>)("textbox")).sendKeys("TestData")

This will type the string "TestData" into the text field. 🔤

To clear text from a text field:

clear()

Syntax:

driver.findElement([By.id](<http://by.id/>)("textbox")).clear()

This will empty any existing text from the field.✂️

Entering a search query:

driver.findElement([By.name](<http://by.name/>)("q")).sendKeys("selenium testing") 🔍
driver.findElement([By.name](<http://by.name/>)("q")).clear() ✂️

Filling out a form:

driver.findElement(By.className("fname")).sendKeys("John")
driver.findElement(By.className("lname")).sendKeys("Doe")✍️

Me: Selenium provides a few useful APIs for interacting with links (i.e. <a> elements):

click()

Syntax:

driver.findElement([By.id](<http://by.id/>)("someLink")).click()

This will simulate a click on the link. 👈

isEnabled()

Syntax:

driver.findElement([By.id](<http://by.id/>)("link")).isEnabled()

This returns true/false if the link can be clicked. 🟢

isDisplayed()

Syntax:

driver.findElement([By.id](<http://by.id/>)("link")).isDisplayed()

This returns true/false if the link is visible on the page. 👁️

driver.findElement(By.linkText("Terms")).click() 📄
isEnabled = driver.findElement(By.partialLinkText("Disabled")).isEnabled()
print(isEnabled)

Last updated