Python 如何在使用Selenium Webdriver单击()之前正确等待页面加载?
此命令在以下情况下间歇性失败:Python 如何在使用Selenium Webdriver单击()之前正确等待页面加载?,python,selenium,Python,Selenium,此命令在以下情况下间歇性失败: driver.find_element_by_id("ch4_loginGuestBtn").click() 我猜我需要做如下的事情 "Element is not clickable" 然而,这在以下方面是失败的: guestlogin_button = wait.until(EC.visibility_of_element_located((By.id, ".ch4_loginGuestBtn"))) actions = ActionCha
driver.find_element_by_id("ch4_loginGuestBtn").click()
我猜我需要做如下的事情
"Element is not clickable"
然而,这在以下方面是失败的:
guestlogin_button = wait.until(EC.visibility_of_element_located((By.id, ".ch4_loginGuestBtn")))
actions = ActionChains(driver)
actions.move_to_element(guestlogin_button).click().perform()
我做错了什么,我该如何修复等待线?您可能需要更改
AttributeError: type object 'By' has no attribute 'id'
到
你可能需要改变
AttributeError: type object 'By' has no attribute 'id'
到
int count=0;
而(计数<4){
试一试{
Webdriverwait wait=新的Webdriverwait(驱动程序,10);
WebElement p=wait.until(ExpectedConditions.elementtobelickable(By.xapth(“”));
driver.findelement(by.xapth(“”)。单击
}
捕获(例外e)
{
System.out.println(“尝试从异常中恢复:-”);
计数=计数+1;
继续;
}
计数=计数+4;
}
int count=0;
而(计数<4){
试一试{
Webdriverwait wait=新的Webdriverwait(驱动程序,10);
WebElement p=wait.until(ExpectedConditions.elementtobelickable(By.xapth(“”));
driver.findelement(by.xapth(“”)。单击
}
捕获(例外e)
{
System.out.println(“尝试从异常中恢复:-”);
计数=计数+1;
继续;
}
计数=计数+4;
}
错误代码但有效:
int count=0;
while (count < 4) {
try {
Webdriverwait wait = new Webdriverwait(driver,10);
WebElement p = wait.until(ExpectedConditions.elementToBeClickable(By.xapth("")));
driver.findelement(by.xapth("")).click
}
catch (Exception e)
{
System.out.println("Trying to recover from a exception :-");
count = count + 1;
continue;
}
count = count + 4;
}
i=0
虽然i代码不好但有效:
int count=0;
while (count < 4) {
try {
Webdriverwait wait = new Webdriverwait(driver,10);
WebElement p = wait.until(ExpectedConditions.elementToBeClickable(By.xapth("")));
driver.findelement(by.xapth("")).click
}
catch (Exception e)
{
System.out.println("Trying to recover from a exception :-");
count = count + 1;
continue;
}
count = count + 4;
}
i=0
虽然我把身份证换成了身份证,但问题还是一样。您链接的帖子似乎没有什么帮助。By
中的其他项目使用大写(By.CSS\u SELECTOR
,By.XPATH
),所以我会尝试By.ID
。更改为ID解决了问题。我将ID更改为ID,仍然是相同的问题。您链接的帖子似乎没有什么帮助。By
中的其他项目使用大写(By.CSS\u SELECTOR
,By.XPATH
),因此我会尝试By.ID
。更改为ID解决了问题。
i=0
while i<1:
try:
driver.find_element_by_id("ch4_loginGuestBtn").click()
i==1
except: