我试图从“我的旅行”网站的出发日历中选择当前日期,但无法通过Selenium和Java找到Web元素

时间:2019-02-27 18:39:33

标签: java selenium selenium-webdriver

onSuggestSelect(suggest) {
  if (!suggest.gmaps) {
    return;
  }

  const components = suggest.gmaps.address_components;
  const address = {
    street: this.findAddressComponent(components, 'street_number', 'short_name') + ' ' + this.findAddressComponent(components, 'route', 'short_name'),
    city: this.findAddressComponent(components, 'locality', 'short_name'),
    state: this.findAddressComponent(components, 'administrative_area_level_1', 'short_name'),
    zip: this.findAddressComponent(components, 'postal_code', 'short_name'),
  }

  this.setState({
    address
  });
}

findAddressComponent(components, type, version) {
  const address = components.find(function(component) {
    return (component.types.indexOf(type) !== -1);
  });

  return address[version];
}

错误:线程“主”中的异常org.openqa.selenium.WebDriverException:未知错误:元素...在点(352,560)不可单击。其他元素将获得点击:

1 个答案:

答案 0 :(得分:0)

看起来像它的readonly字段。我尝试过JavaScript Executor来设置值。 请尝试以下代码,看看是否有帮助。

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("document.getElementById('hp-widget__depart').value='2 Mar,Fri';");

OR

WebElement elementdept=driver.findElement(By.xpath("//input[@mt-id='departDate']"));
elementdept.click();        
driver.findElement(By.cssSelector("a.ui-state-active")).click();