简体   繁体   中英

Webdriver xpath multiple matching

For some reason this is not working for me

driver.findElement(By.xpath("//textarea[@id[contains(., 'explanation')]] or input[@id[contains(., 'notes')]]")).sendKeys("auto-generated text");

Where can I find syntax rules for joining multiple matching conditions?

EDIT: Just copying explanation to my question >

I want xpath to match one of the elements depending on the page being tested. Two pages have different elements with different id's and tags, so in one case it would match "textarea", in another - "input". I could solve this with one if statement, but I was just curious if xpath could work in this case.

The or operator is the Boolean operator which cannot be used here. I assume that you need the union of node sets which is represented by the | operator. Be aware that when you make the replacement you have to think about how the nesting levels of both tags textarea and input relate to each other.

//*[((name(.)='textarea') and contains(@id,'explanation')) or ((name(.)='input') and contains(@id,'notes'))]应该工作,但我不能决定它是否比if ;-)更好

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM