Hello, I will put the code that you need for open some saved profile in Firefox with Selenium.
Tag: selenium
Mouse up of a WebElement (Selenium and Java)
Move the mouse up of a controller/WebElement is simple, is just put this line of code:
WebElement valoratual = driver.findElement(By.className(“product-description-catalog-item”));
Robot robot = new Robot();
robot.mouseMove(valoratual.getLocation().getX(), valoratual.getLocation().getY());
Yes, you have to catch the X and Y in the page and the robot will put the mouse over thispoint.
Bye bye 🙂
Do you need scroll the page ? (Selenium and javascript)
If you need scroll the page for example take a screenshot in a browser different of Firefox (Yes, the selenium have a problem to take a screenshot of the entire page when you are in a different browser like, IE)
So we have to create a function that take a screenshot of parts of the page, and this function helps you to scroll the page.
First you have to import the libraries:
import org.openqa.selenium.JavascriptExecutor;
After the code:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(“window.scrollTo(0,Math.max(document.documentElement.scrollHeight,”
+ “document.body.scrollHeight,document.documentElement.clientHeight));”);
After this, the driver will scroll until the end of the current page.
I hope that I help you 🙂
Mark element in the page with red border (Javascript with Selenium)
Hello again, now I will give a tip of Selenium, for mark the element that you want and before this, you can take a screenshot for evidence.
First you have to import this libraries:
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
After this, you have to call the javascript executor and give the id or other thing for find the element:
JavascriptExecutor js = (JavascriptExecutor) driver; // change the name of your WebDriver
WebElement element = driver.findElement(By.id(“element“)); // change the localizator
js.executeScript(“arguments[0].style.border=’3px solid red'”, element); // change the name of your variable
This is very usefull for mark the element in the page.
So, just this ! Bye bye 🙂
How can I call the drivers(browsers) in Selenium with java ?
It’s simple !
you have to call the import > import org.openqa.selenium.WebDriver; and others about the browsers, like: import org.openqa.selenium.firefox.FirefoxDriver; (calls Firefox)
After this, in the class Main, declare driver:
WebDriver driver;
and Quit:
Quit quit = new Quit();
So… you have now choose what is the browser and calls the profile and set the configs, like proxy (for this reason you have to create a profile)
public class Main {
public static void main(String[] args) throws Exception {
FirefoxProfile profile = new FirefoxProfile(); // create a profile of Firefox
profile.setPreference(“network.proxy.type”, 0); // Don’t use proxy
driver = new FirefoxDriver(profile); // calls the browser with the configs of the profile
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); // config the timeouts for load a page
driver.get(site); // change site for the url that your driver will open.
quit.tearDown(driver); // quit the driver.
}
}
You have to create the class that close the driver in class Main.
public class Main {
public static class Quit {
public void tearDown(WebDriver driver) {
driver.close();
driver.quit();
}
}
and finish !
This is the first step for create a automation with selenium. Create a driver and open the browser !
Good studies for all, bye !
How we can find a line in some table with Webdriver (Selenium) ?
Hi guys, I’m very occupied in the last months, but I will post a text about catch the lines and values in some table with Webdriver (selenium) in language java. Yes, I am changing a little the subjects, this time I will help the testers, who do automation of sites.
It’s easy if you use XPath.
This table:
| Apples | 44% |
| Bananas | 23% |
| Oranges | 13% |
| Other | 10% |
/html/body/div[1]/div/div[4]/div[2]/div[2]/table/tbody/tr[1]
You catched the first line.
If you want catch the second line, just change the number:
/html/body/div[1]/div/div[4]/div[2]/div[2]/table/tbody/tr[2]
It’s more easy than you expected, not ?
if you want catch all the text of all lines, just write the code:
WebElement listatable = driver.findElement(By.className(“reference”));
for (int i = 0; i < listatable.getLength(); i++) {
WebElement line = driver.findElement(By.xpath(“/html/body/div[1]/div/div[4]/div[2]/div[2]/table/tbody/tr[” + i + “]”));
line.getText();
}
Fine, now you can catch the text of each line in this table !
I hope has helped the initial testers in something.
Bye bye !