如何执行多个操作并通过selenium-webdriver在URL http://www.spicejet.com/上单击带有文本的链接作为“会员登录". [英] How to perform multiple actions and click on the link with text as Member Login on the url http://www.spicejet.com/ through selenium-webdriver
本文介绍了如何执行多个操作并通过selenium-webdriver在URL http://www.spicejet.com/上单击带有文本的链接作为“会员登录".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了以下代码,但它不是鼠标悬停并单击会员登录"
I tried the below code but it is not mouse hovering and clicking on 'Member login'
WebElement lgn = driver.findElement(By.id("ctl00_HyperLinkLogin"));
WebElement ssm = driver.findElement(By.xpath("//a[contains(text(), 'SpiceCash/SpiceClub Members')]"));
WebElement cgm = driver.findElement(By.xpath("//a[contains(text(),'Member Login')]"));
Actions a1 = new Actions(driver);
a1.moveToElement(lgn).moveToElement(ssm).moveToElement(cgm).click().build().perform();
推荐答案
要在文本为会员登录的元素上调用 click()
,首先,您必须将鼠标悬停在元素上,文本为登录/注册,然后将将鼠标悬停在元素上,文本为 SpiceCash/SpiceClub成员 strong>然后将文本为会员登录的元素的 WebDriverWait 设为可点击,您可以使用以下解决方案:
To invoke click()
on the element with text as Member login, first you have to Mouse Hover over the element with text as LOGIN / SIGNUP, then Mouse Hover over the element with text as SpiceCash/SpiceClub Members then induce WebDriverWait for the element with text as Member Login to be clickable and you can use the following solution:
-
代码块:
Code Block:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Spicejet_member_login {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.spicejet.com/");
new Actions(driver).moveToElement(new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("a.link#ctl00_HyperLinkLogin")))).build().perform();
new Actions(driver).moveToElement(new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//li[@class='hide-mobile']/a[contains(.,'SpiceCash/SpiceClub Members')]")))).build().perform();
new WebDriverWait(driver, 7).until(ExpectedConditions.elementToBeClickable(By.xpath("//li[@class='hide-mobile']//ul/li/a[@href='https://book.spicejet.com/Login.aspx' and contains(.,'Member Login')]"))).click();
}
}
浏览器快照:
Browser Snapshot:
这篇关于如何执行多个操作并通过selenium-webdriver在URL http://www.spicejet.com/上单击带有文本的链接作为“会员登录".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文