简体   繁体   English

如何通过 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

在此处输入图片说明

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();

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:要以成员登录名调用元素上的click() ,首先必须将鼠标悬停在文本为LOGIN / SIGNUP的元素上,然后将鼠标悬停在文本为SpiceCash/SpiceClub 成员的元素上,然后为该元素引入WebDriverWait文本作为会员登录可点击,您可以使用以下解决方案:

  • 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:浏览器快照:

spicejet_member_login

You can try to add waits between your moveToElement() calls您可以尝试在 moveToElement() 调用之间添加等待

WebDriverWait wait = new WebDriverWait(WebDriverRunner.getWebDriver(), 10); wait.until(ExpectedConditions.visibilityOf(element))

where the "element" is your menu that should appear on hover.其中“元素”是应该出现在悬停时的菜单。

Or you can use ready solution Selenide framework which is built on top of the Selenium and has built in hover method and waits which help to handle page dynamics By this link you can find an example of hover() method usage.或者您可以使用现成的解决方案Selenide框架,该框架构建在 Selenium 之上,并内置了悬停方法和等待,有助于处理页面动态通过此链接,您可以找到悬停()方法使用的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Selenium Java 处理 https://www.spicejet.com/ 的 PASSENGERS 字段的静态下拉列表 - How to handle the static dropdowns of PASSENGERS field of https://www.spicejet.com/ using Selenium Java 如何通过Selenium Webdriver单击“隐藏”链接 - How to click on Hidden link through Selenium Webdriver 如何在Selenium WebDriver中单击链接文本 - How to click link text in selenium webdriver 使用 Selenium-WebDriver 通过 AutoIt 上传多个文件 - Multiple file upload through AutoIt using Selenium-WebDriver 如何使用 selenium-webdriver 和 Java 单击日历图像图标 - How to click the Calendar image icon using selenium-webdriver and Java 如何使用 java 通过 selenium-webdriver 和 Java 鼠标 hover - How to mouse hover using java through selenium-webdriver and Java 如何通过Selenium-WebDriver正确查找元素以用于输入目的 - How to properly find an element through Selenium-WebDriver for input purposes Selenium Webdriver Java:无法通过Chrome中的操作执行点击操作 - Selenium Webdriver Java: Unable to perform click operation by Actions in Chrome 如何使用 selenium-Webdriver 处理 FileUpload - How to handle FileUpload using selenium-Webdriver 无法通过 Selenium 和 Java 在 https://spicejet.com 中选择出发日期 - Unable to select depart date in https://spicejet.com through Selenium and Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM