[英]How to click on the button if there is no ClassName and ID is not working in selenium webdriver
from selenium import webdriver
import time
driver = webdriver.Firefox()
try:
driver.get("URL Link")
time.sleep(10)
driver.find_element_by_id("ess.myAccount.Label").click()
except:
print("Requested page is not opening")
driver.close()
单击该按钮的另一种方法是HTML Source--Primary Account
在下面用作cssSelector并单击:
a#ess\\.homeAccount\\.Label[onclick$='return false;']
要么
a#ess\\.homeAccount\\.Label[onclick$='return false;'][href$='#']
要么
a[id^='ess'][onclick$='return false;'][href$='#']
你也可以用这个
driver.find_element_by_id("ess\\.myAccount\\.Label").click()
如果id不起作用,那么您可以尝试使用其他定位器,通过它们我们可以指出特定的必需元素。 通过使用提供的HTML代码,您可以尝试
xpath:
//a[@id='ess.homeAccount.Label'] //如果id无效,则使用id的xpath可能有效
// a [包含(text(),'主帐户')]
谢谢,穆拉利
您可以单击父元素,该元素实际上具有onclick
事件
driver.find_element_by_class_name('BM').click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.