如何解决如何使用Selenium和Java在https://www.goindigo.in/上单击下拉列表并增加成人乘客的数量
我正在尝试访问Indigo网站https://www.goindigo.in/
我已经写了代码:
System.setProperty("webdriver.chrome.driver","D:\\New folder\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.goindigo.in/");
Thread.sleep(2000);
driver.findElement(By.cssSelector("input.form-
control.hpBookingForm.passengerInputField.pax-class-count")).click();
for(int i=1;i<5;i++)
{
driver.findElement(By.xpath("/html/body/div[27]/div/div/div[2]/ul/li[1]/div/button[2]")).click();
}
我无法增加乘客人数。请检查。
解决方法
将for循环更改为:
for(int i=0;i<5;i++)
{
driver.findElement(
By.xpath("/html/body/div[27]/div/div/div[2]/ul/li[1]/div/button[2]")
).click();
}
,
引起一些等待,更改xpath并修复for循环。另外,以跨度而不是按钮为目标,否则会出错。
WebDriverWait wait = new WebDriverWait(driver,30);
WebElement adult =wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div/div/div[2]/ul/li[1]/div/button[2]//span")));
for(int i=1;i<5;i++)
{
adult.click();
}
要更改其他名称,请将li [1]更改为li [2],依此类推。 导入以下
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
不要使用Thread.sleep()使用
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
导入
import java.util.concurrent.TimeUnit;
最好是等待而不是隐式等待,就像我上面在上面给出的示例一样。
,问题不完整,我们不知道错误日志是什么。
因此,根据您的需要,我给出以下代码示例。
在代码中,我做了两件事以使 +元素被掩盖。
- 关闭 cookie同意横幅
- 滚动到该元素
$imageName = time() . '.' . $request->gambar->getClientOriginalExtension();
$imagePath = 'images/' . $imageName;
Storage::put($imagePath,file_get_contents($request->gambar->getRealPath()));
,
要在USE [database]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[INS_MAJ_PATERNITE_V2]
@retcode int OUTPUT,@message VARCHAR(255) OUTPUT
AS
BEGIN
---- how many times parents appears in cb column
WITH nb_parent_dans_cb
AS
(
SELECT count(*) AS nb,cb
FROM Paternite
where parent in (select cb from paternite)
GROUP BY cb
)
UPDATE Paternite
SET Test_paternite = nb_parent_dans_cb.nb
FROM Paternite
INNER JOIN nb_parent_dans_cb ON paternite.cb = nb_parent_dans_cb.cb
END
下拉列表中增加成人乘客的数量,您需要为click()
引入WebDriverWait,并且可以使用以下任一方法Locator Strategies:
-
elementToBeClickable()
:xpath
-
浏览器快照:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。