我正在尝试使用角度为5的量角器选择与客户付款方式相关的单选按钮,但是单选按钮选择一旦被选中则不稳定,而十次则不稳定。 在网络结帐中单击单选按钮的代码:
browser.driver.findElement(by.xpath("//input[@name='paymentMethod' and @type='radio' and @id='874904645420181210']"));
browser.driver.actions().mouseMove(element(by.xpath("//input[@name='paymentMethod' and @type='radio' and @id='874904645420181210']"))).perform();
var e = element(by.xpath("//input[@name='paymentMethod' and @type='radio' and @id='874904645420181210']"));
browser.wait(EC.presenceOf(e), 10000);
element.all(by.xpath("//input[@name='paymentMethod' and @type='radio'")).then( async function(elm){
await browser.waitForAngular();
await browser.sleep(180000);
await elm[0].click();
await e.click();
await browser.waitForAngular();
await browser.sleep(180000);
答案 0 :(得分:0)
调用browser.driver.findElement
时,它将找到元素而无需等待Angular稳定性。基本上,您是直接调用selenium-webdriver客户端,结果可能会有所不同。
我将避免使用显式睡眠和调用waitForAngular。还要考虑不要使用xpath来标识您的Web元素。这可能导致难以维护测试。
// Nit: Prefer not to use xpath because these can be brittle.
// Reference http://www.protractortest.org/#/style-guide
const paymentMethod = element(by.xpath("//input[@name='paymentMethod' and @type='radio' and @id='874904645420181210']"));
// We should wait to see if the element is present before doing anything.
// This should also wait for angular stability with waitForAngular
browser.wait(EC.presenceOf(paymentMethod), 10000);
不同的点击方式...
警告:由于W3C动作API与浏览器驱动程序提供程序和selenium-webdriver客户端一起不断变化,因此您可能会遇到问题。
// browser.driver.actions() mouseMove takes a WebElement object.
// So just moving the mouse does not click. You might want to click on it?
// Also assuming that this is the radio button
const paymentMethodWebEl = await paymentMethod.getWebElement();
await browser.driver.actions().mouseMove(paymentMethodWebEl).click().perform();
非常标准的点击。
await paymentMethod.click();
// This might be the same step as above to click on a payment radio button
const paymentMethods = element.all(by.xpath("//input[@name='paymentMethod' and @type='radio'"));
// http://www.protractortest.org/#/api?view=ElementArrayFinder.prototype.get
await paymentMethods.get(0).click();