I have a link that stays on same page but scrolls down the screen
if you go to websiste test.naimi.me and click here:
the link should scroll you down a little bit, how to test this action in selenium webdriver, i use testng and write in java.
EDIT:@Helping hands
package erjan.test.naimi.me;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.testng.Assert;
public class SpecialistLoads {
WebDriver firefox ;
@Test
public void main() {
//By.xpath("//a[@href=\"/astana/\"]/img") )) ;
WebElement all_specs = firefox.findElement(By.xpath("//a[@href=\"/astana/#specialists\"]")) ;
all_specs.click();
String all_specalists_url = firefox.getCurrentUrl();
Assert.assertEquals(all_specs, all_specialists_url );
}
@BeforeMethod
public void beforeMethod() {
firefox = new FirefoxDriver() ;
firefox.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Launch the website
firefox.get("http://test.naimi.me");
}
@AfterMethod
public void afterMethod() {
firefox.quit();
}
}
The link the red arrow points to has html code:
a data-toggle="menu" href="/astana/#specialists">Все специалисты</a>
To test it, I would make usage of an indirect check.
Verify if a botton element of the page is visible after activating the link. I am more comfortable with the python code but in java the call should be:
WebElement.isDisplayed()
to check if an element is visible
isDisplayed() is the method used to verify presence of a web element within the webpage. The method is designed to result a Boolean value with each success and failure. The method returns a “true” value if the specified web element is present on the web page and a “false” value if the web element is not present on the web page.
Example:
boolean footer_loaded=driver.findElement(By.id(“footer”)).isDisplayed();
If link is not visible when page load then you can use isdisplayed method like below :
WebElement link = driver.findElement(By.xpath(yourlinkxpath"));
If(link.isDisplayed())
{
// Write code to click on link
}
else
{
// Write code to skip it
}
To find link element you can use Id , xpath , class anything.
You can check the size of an element and its position relative to the viewport by Element.getBoundingClientRect() . You'll need to use driver.executeScript() for that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.