java - 通过 selenium 在 paytm 主页上发起搜索的问题
问题描述
以下是我想通过 Selenium 在 paytm 上自动化的步骤。
脚步:-
1.启动支付宝。
2.在paytm页面顶部显示的搜索框中输入任何关键字。例如“移动”
3.按回车键导航到搜索结果页面。
问题:在搜索框中写入的关键字被自动删除
我的代码:
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class XPath {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\ProgramFiles\\Work\\ChromeDriver\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://paytm.com");
//driver.findElement(By.xpath("//input[@placeholder='Search for a Product , Brand or Category']")).sendKeys("mobile");
driver.findElement(By.xpath("//input[@placeholder='Search for a Product , Brand or Category']")).sendKeys(Keys.ENTER);
}
}
解决方案
问题是您需要等待页面完全加载。有一个在页面加载时运行的 ajax 脚本,它在搜索输入文本框上做了一些工作。当页面完全加载时,body 标签包含一个 style 属性。通过使用 a和a来等待此属性。ExpectedConditions
attributeCOntains
WebDriverWait
试试这个代码 -
new WebDriverWait(driver, 3).until(ExpectedConditions.attributeContains(By.tagName("body"), "style", "overflow: visible;"));
WebElement srch = driver.findElement(By.cssSelector("input[type='search']"));
srch.sendKeys("Hello");
推荐阅读
- c# - 如何使用 c# 打开 SAP Business One 报表查看器
- python - 如何更改熊猫箱线图中的y标签步骤
- python - 使用 Pandas DataFrame 连续计算过去间隔的平均值
- d3.js - 如何使用 d3 自定义符号创建药丸矩形
- r - 如何在将多个图排列在一起时修改我的图例以不使用 ggplot2 折叠图
- javascript - 如何控制鼠标滚动事件,然后在 html、body 上制作动画?
- html - 如何为选择标签中的所有选项添加图像?
- angular - ng-serve 加载太慢
- arrays - 不同大小数组(锯齿状数组)的 Python 集合,Dask?
- typescript - 如何向应用程序添加动态标题 - VueJS