selenium 坐标点击div_如何使用seleniumpython动态地单击按钮或div标记,直到它从页面中消失?...

这是针对您的问题的java解决方案。对于python也可以使用相同的逻辑public static void loadAll(WebDriver driver) {

while (true) {

//Using findElements to get list of elements so that it wont throw exception if element is not present

List elements = driver.findElements(By.xpath("//div[@class='load-more']"));

//If the size is zero that means load more element is not present so breaking the loop

if (elements.isEmpty()) {

break;

}

//Assigning first element to a variable

WebElement loadEl = elements.get(0);

//Getting text of element

String text = loadEl.getText().toLowerCase();

//check if text contains load more, as, if it is loading it will have ... ,so we cant click at that time

if (text.contains("load more")) {

loadEl.click();

}

//if text contains 1 to 4 means [for ex "Load More 4"] this is the last click so breaking the loop

if (text.matches("load more [1-4]")) {

break;

}

}

System.out.println("Done");

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值