Saltar al contenido

cómo crear una instancia de webdriver en un ejemplo de código de selenio

Ejemplo 1: cómo alojar scripts de automatización web de selenium en línea

# The same code that HomelessHorse wrote but in Python

from selenium importwebdriver					# pip install selenium towork
from selenum.webdriver.common.keys importKeys
driver =webdriver.Chrome()				# Specifying which browser touse
driver.get("https://www.google.com")	# The url of the website tovisit
element = driver.find_element_by_name("q") # Find the searchbar element which has the name "q"
element.send_keys("BrowserStack")		# Send in the word "BrowserSTack"
element.send_keys(Keys.RETURN)	# Send in the ReturnKey(EnterKey)print(driver.title)		# Print the title of the webpage in the console
driver.quit()		# Close the webdriver

Ejemplo 2: ejecutar pruebas de Seleniam

// Sample test in Java to run Automate session.importorg.openqa.selenium.By;importorg.openqa.selenium.Platform;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.WebElement;importorg.openqa.selenium.remote.DesiredCapabilities;importorg.openqa.selenium.remote.RemoteWebDriver;importjava.net.URL;publicclassJavaSamplepublicstaticfinalString AUTOMATE_USERNAME ="YOUR_USERNAME";publicstaticfinalString AUTOMATE_ACCESS_KEY ="YOUR_ACCESS_KEY";publicstaticfinalString URL ="https://"+ AUTOMATE_USERNAME +":"+ AUTOMATE_ACCESS_KEY +"@hub-cloud.browserstack.com/wd/hub";publicstaticvoidmain(String[] args)throwsExceptionDesiredCapabilities caps =newDesiredCapabilities();
    caps.setCapability("os_version","8");
    caps.setCapability("resolution","1920x1080");
    caps.setCapability("browser","Chrome");
    caps.setCapability("browser_version","latest-beta");
    caps.setCapability("os","Windows");
    caps.setCapability("name","BStack-[Java] Sample Test");// test name
    caps.setCapability("build","BStack Build Number 1");// CI/CD job or build nameWebDriver driver =newRemoteWebDriver(newURL(URL), caps);
    driver.get("https://www.google.com");WebElement element = driver.findElement(By.name("q"));
    element.sendKeys("BrowserStack");
    element.submit();System.out.println(driver.getTitle());
    driver.quit();

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *