I’m tring to select this dropdown list using PHP/selenium.
My code is below:
sleep(3); $driver->findElement( WebDriverBy::xpath("//*[@id='main']/form/section[2]/mer-select[1]/div/label/div[2]/select") ) ->findElement( WebDriverBy::cssSelector("option[value='2']") )->click();
and I tried all attempts suggested in this post. Non of them works.
I want your help. Thank you.
Advertisement
Answer
If this css:
select.input-node.medium.placeholder[name='category1']
or this xpath:
//select[contains(@class,'input-node medium placeholder') and @name='category1']
represent unique node in HTMLDOM which means 1/1 matching node then you can use the below code to select the desired option from the drop down.
Please check in the dev tools
(Google chrome) if we have unique entry in HTML DOM
or not.
Steps to check:
Press F12 in Chrome
-> go to element
section -> do a CTRL + F
-> then paste the xpath/css
and see, if your desired element
is getting highlighted with 1/1
matching node.
Code:
$select = new WebDriverSelect($driver->findElement(WebDriverBy::cssSelector("select.input-node.medium.placeholder[name='category1']"))); $select->selectByValue('3');