如何通过XPath选择相邻元素?

时间:2016-08-11 12:22:11

标签: html xml xpath selenium-webdriver

下拉列表包含以下代码。如何为这个元素编写XPath?

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(20) COLLATE utf8_persian_ci NOT NULL,
  `password` varchar(65) COLLATE utf8_persian_ci NOT NULL,
  `name` varchar(20) COLLATE utf8_persian_ci NOT NULL,
  `family` varchar(20) COLLATE utf8_persian_ci NOT NULL,
  `birthDay` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
  `email` varchar(20) COLLATE utf8_persian_ci NOT NULL,
  `mobileNumber` varchar(15) COLLATE utf8_persian_ci NOT NULL,
  `verifyCode` varchar(5) COLLATE utf8_persian_ci NOT NULL,
  `photoUri` varchar(50) COLLATE utf8_persian_ci NOT NULL,
  `ebanNumber` varchar(20) COLLATE utf8_persian_ci NOT NULL,
  `status` tinyint(1) NOT NULL,
  `createdAt` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `updatedAt` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci AUTO_INCREMENT=35 ;

1 个答案:

答案 0 :(得分:5)

这个XPath,

//button[normalize-space() = 'Select door']

将根据其选择门标签选择显示的button元素。

这个XPath,

//button[normalize-space()='Select door']/following-sibling::div[@class='dropdown-menu'][1]

将选择紧随其后的dropdown-menu div