当按钮webelement是动态的时,如何在SeleniumWebDriver中查找xpath
下面是页面的html,我需要获取按钮的xpath,它将在SeleniumWebDriver中工作。或者有没有办法点击SeleniumWebDriver中的按钮 如果它是java的,那就太好了,否则python和其他语言也会受到赞赏当按钮webelement是动态的时,如何在SeleniumWebDriver中查找xpath,selenium,button,xpath,selenium-webdriver,Selenium,Button,Xpath,Selenium Webdriver,下面是页面的html,我需要获取按钮的xpath,它将在SeleniumWebDriver中工作。或者有没有办法点击SeleniumWebDriver中的按钮 如果它是java的,那就太好了,否则python和其他语言也会受到赞赏 <button style="" onclick="saveAndContinueEdit('http://192.168.1.99/cue_extensions/magento1.9/index.php/admin/catalog_product/save/b
<button style="" onclick="saveAndContinueEdit('http://192.168.1.99/cue_extensions/magento1.9/index.php/admin/catalog_product/save/back/edit/tab/{{tab_id}}/id/899/key/6ed7b01b3a2136d6ff896d9380e281d5/')" class="scalable save" type="button" title="Save and Continue Edit" id="**id_636f54090db18b58eecba78e9e6aa6b7**">
<span><span><span>Save and Continue Edit</span></span></span>
</button>
保存并继续编辑
但是当我下次登录时,html会更改为
<button style="" onclick="saveAndContinueEdit('http://192.168.1.99/cue_extensions/magento1.9/index.php/admin/catalog_product/save/back/edit/tab/{{tab_id}}/id/903/key/29d8597a8ec8f63d9b09addae444d4c0/')" class="scalable save" type="button" title="Save and Continue Edit" id="id_c2fe56a74ef2a166dcf0ae4ed7f8e391">
<span><span><span>Save and Continue Edit</span></span></span>
</button>[![enter image description here][1]][1]
保存并继续编辑
[![在此处输入图像描述][1][1]
您可以使用以下xpath-
//span[@title="Save and Continue Edit"]
在Java中:
driver.findElement(By.xpath("//button[@title='Save and Continue Edit']")).click();
用python
driver.find_elements_by_xpath("//button[@title='Save and Continue Edit']").click()
请尝试以下操作:
在Java中:
driver.findElement(By.Xpath("//span[contains(text(), 'Save and Continue Edit')]")).click();
driver.find_element_by_xpath("//span[contains(text(), 'Save and Continue Edit')]").click()
Python中的:
driver.findElement(By.Xpath("//span[contains(text(), 'Save and Continue Edit')]")).click();
driver.find_element_by_xpath("//span[contains(text(), 'Save and Continue Edit')]").click()
如果您可以假定标题始终为“保存并继续编辑”(即Magento后端语言未更改),请使用 如前所述。更可靠的方法是通过
onclick
属性进行搜索,例如:
//button[starts-with(@onclick,"saveAndContinueEdit(")]
在java中,您可以使用以下命令找到:
driver.findElement(By.Xpath(//按钮[包含(,'Save and Continue Edit')))))。单击()代码>不,不能,这是非法的XPath。也许你的意思是/*[@..]
,或者///span[@…]
?`必须始终后跟节点测试。