我需要使用 Selenium 使用以下 HTML 查找文本并將其輸入到文本欄位中:
<input slot="input" class="form-control" id="abc-gib-input-38303-70ft6l7k2g" aria-invalid="false" aria-required="true" aria-labelledby="label-abc-gib-input-38303-70ft6l7k2g label-abc-form-38302-42pti7lz8z" aria-describedby="help-text-abc-gib-input-38303-70ft6l7k2g feedback-abc-gib-input-38303-70ft6l7k2g feedback-abc-form-38302-42pti7lz8z help-text-abc-form-38302-42pti7lz8z" type="text" placeholder="" name="login" autocomplete="off">
問題是每次頁面重新加載 id 更改 - 這部分保持相同的“abc-gib-input-38303-”。
如何選擇這個元素?
我試過:
await driver.findElement(By.xpath('//*[contains(@id,"abc-gib-input"]'))
它不起作用。
uj5u.com熱心網友回復:
您)的 XPath 運算式中缺少右括號。
代替
await driver.findElement(By.xpath('//*[contains(@id,"abc-gib-input"]'))
它應該是
await driver.findElement(By.xpath('//*[contains(@id,"abc-gib-input")]'))
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/409790.html
標籤:
