[英]How to handle the static dropdowns of PASSENGERS field of https://www.spicejet.com/ using Selenium Java
[英]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
我嘗試了以下代碼,但它不是鼠標懸停並單擊“會員登錄”
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()
,首先必須將鼠標懸停在文本為LOGIN / SIGNUP的元素上,然后將鼠標懸停在文本為SpiceCash/SpiceClub 成員的元素上,然后為該元素引入WebDriverWait文本作為會員登錄可點擊,您可以使用以下解決方案:
代碼塊:
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(); } }
瀏覽器快照:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.