![](/img/trans.png)
[英]How do I animate this graph so that the dot moves and the green line plots over a different range for each element in loop?
[英]How do I make it so that if XPATH doesn't see an element on a website, it skips that line and moves on to the next line?
如何使它在 XPATH 沒有看到頁面上的元素時跳過該元素並移至下一行? 我的代碼是:
1. driver.find_element_by_xpath('//img[@alt = "Black"]').click()
然后如果它沒有找到第一個元素,它會跳過並嘗試找到:
2. driver.find_element_by_xpath('//*[@id="add-remove-buttons"]/input').click()
我猜這與“如果 ___ 顯示,點擊,否則如果 ____ 點擊”有關,盡管我不確定如何格式化。
在 xpath 中,您可以獲得兩個節點集的並集
driver.find_element_by_xpath(
'//img[@alt = "Black"]|//*[@id="add-remove-buttons"]/input').click()
使用 try 和 catch 塊並捕獲 ElementNotFoundException 異常 Java:
try{
//your code to find element
}
catch(ElementNotFoundException)
{
//print element not found
}
// find another element and perform action
參考-https://www.w3schools.com/python/python_try_except.asp
Python:
try:
//your code
except ElementNotFoundException:
print("ELEMENT NOT fOUND")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.